开发者社区> 问答> 正文

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:官方给出解释
screenshot

展开
收起
a123456678 2016-07-27 10:57:10 3054 0
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");
    
    }
    2019-07-17 20:00:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载