QQ登录集成步骤
1.去腾讯开放平台注册开发者,然后创建应用,完善应用信息,提交审核,审核成功后就可以使用APP ID和APP KEY。
2.下载官方SDK,参考官方文档,也可以查看官方demo
3.配置环境,导入库TencentOpenAPI.framework和TencentOpenApi_IOS_Bundle.bundle,再导入依赖框架Security.framework、libiconv.dylib、SystemConfiguration.framework、CoreGraphics.Framework、libsqlite3.dylib、CoreTelephony.framework、libstdc++.dylib、libz.dylib
4.在AppDelegate.m里面导入
#import <TencentOpenAPI/TencentOAuth.h>
再导入方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
return [TencentOAuth HandleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [TencentOAuth HandleOpenURL:url];
}
5.在需要登录的文件里面导入
#import<TencentOpenAPI/TencentOAuth.h>,挂上代理TencentSessionDelegate,再创建
TencentOAuth *_tencentOAuth;
NSMutableArray *_permission;
在viewDidLoad里面加入
NSString *openapi =@"1103297850";
_tencentOAuth = [[TencentOAuth alloc]initWithAppId:openapi andDelegate:self];
_permission = [NSMutableArray arrayWithObjects:kOPEN_PERMISSION_GET_USER_INFO,nil];
[_tencentOAuth authorize:_permission inSafari:NO];
- (void)tencentDidNotNetWork
{
NSLog(@"没有网络");
}
- (void)tencentDidNotLogin:(BOOL)cancelled
{
NSLog(@"登录失败");
}
- (void)tencentDidLogin
{
NSLog(@"登录成功");
NSLog(@"token===%@",[_tencentOAuth accessToken] );
NSLog(@"openId===%@",[_tencentOAuth openId]) ;
NSLog(@"appid === %@",[_tencentOAuth appId]);
}
8.配置一下URL Types
点击targets -> info -> URL Types ,添加URL Schemes为tencent1103297850
至此,运行,能够进行QQ登录,如果有应用,跳转应用登录,没有则跳转网页登录。
备注:刚申请的腾讯开发者账号可能没有权限跳转网页登录,需人工联系客服。
demo下载地址:http://download.csdn.net/detail/baidu_21172753/8362197