在模拟器上登录,执行了代码
[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:官方给出解释
.在 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");
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。