IOS 模拟器使用腾讯 SDK 登录问题


在模拟器上登录,执行了代码


 [tencentOAuth authorize:permissions inSafari:NO];

在模拟器上显示提示没有安装最新版的QQ空间客户端。
但是SDK里的Demo却可以正常打开输入帐号密码的页面。

贴上主要代码


 **ViewController.h**

@interface PersonalCenterViewController : UIViewController <TencentSessionDelegate>{
    TencentOAuth* tencentOAuth;
    NSMutableArray* permissions;
}
@property (weak, nonatomic) IBOutlet UIButton *TencentOAuth;

@end

**ViewController.m**
- (void)viewDidLoad
{
 permissions = permissions = [NSArray arrayWithObjects:@"get_user_info", @"add_t", nil] ;
    NSString* appid = @"10107****";
    tencentOAuth = [[TencentOAuth alloc] initWithAppId:appid andDelegate:self];
    tencentOAuth.redirectURI = @"www.qq.com";
}



-(IBAction)TencentOAuth:(id)sender {
    [tencentOAuth authorize:permissions inSafari:NO];
}

update:官方给出解释

腾讯 qq登录 ios sdk

我要我的滋味 10 years, 1 month ago

我最终放弃了这个 SDK(腾讯有很多 SDK 的),使用腾讯微博的 SDK

第三方登录 SDK 界最烂的是人人毋庸置疑,其次是腾讯,QQ、空间、微信、腾讯微博各自一套 SDK 是闹哪样。

这是今天早上使用 腾讯开放平台 被折磨的半死不活的时候写的微博。这是我遇到的 问题 。而且这种登录方式似乎必须要求有 QQ 空间客户端?放弃这个 SDK,转向了腾讯微博开放平台。

1.创建新的接入应用获取 Key、Secret

这是 链接 ,不多说。

2.下载SDK

SDK 在 github 上。


 git clone https://github.com/heloyue/TCWeiboSDK

3.加入工程

  • 把文件夹中的 doc 文件夹删除,Xcode 会在编译的时候弹出警告(内含 html、css 等文件)
  • 把三个 .a 文件删除到只剩 libTCWeiboSDK.a 不然编译会报错

    linker command failed with exit code 1 (use -v to see invocation)

  • 引入库:Account.framework, Security.framework 和 Social.framework。
  • TARGET => info =》URL Types,新增一个。URL Schemes 中填:wb88888888(88888888为 Key 值)

4.开始写代码

1.在 AppDelegate.h 中

加入


 @property (strong, nonatomic) PersonalCenterViewController *viewController;//PersonalCenterViewController 是我的 ViewController 这里作为例子,替换成你的

2.在 AppDelegate.m 中

实现这两个方法


 -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [self.viewController.weiboApi handleOpenURL:url];//这里的 weiboApi 待会儿再声明
}

//Available in iOS 4.2 and later.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [self.viewController.weiboApi handleOpenURL:url];
}

3.在 ViewController.h 中

导入头文件


 #import "WeiboApi.h"

声明 weiboApi


 @interface PersonalCenterViewController : UIViewController<WeiboRequestDelegate,WeiboAuthDelegate>{
WeiboApi* weiboApi;
}
@property (weak, nonatomic) IBOutlet UIButton *OAuth;

@property (nonatomic,retain) WeiboApi* weiboApi;
@end

4.在 ViewController.m 中

  • 实例化 weiboApi

      
       weiboApi = [[WeiboApi alloc]initWithAppKey:Key andSecret:Secret andRedirectUri:REDIRECTURI andAuthModeFlag:0 andCachePolicy:0] ;
      
     
  • 实现回调函数

      
       //授权成功的回调函数
    - (void)DidAuthFinished:(WeiboApiObject *)wbobj
    {
     NSString *str = [[NSString alloc]initWithFormat:@"accesstoken = %@\r\n openid = %@\r\n appkey=%@ \r\n appsecret=%@ \r\n refreshtoken=%@ ", wbobj.accessToken, wbobj.openid, wbobj.appKey, wbobj.appSecret, wbobj.refreshToken];
     self.result.text = str;
    
     NSLog(@"result = %@",str);
    
     //注意回到主线程,有些回调并不在主线程中,所以这里必须回到主线程
    //    dispatch_async(dispatch_get_main_queue(), ^{
    //        
    //        [self showMsg:str];
    //    });
    
    
    // NSLog(@"after add pic");
    
    }
      
     

大功告成

蔚蓝D瓶子 answered 10 years, 1 month ago

Your Answer