QQSDK
看官网的文档,确实让人头疼的一件事,说是两个资源文件,就找到了一个(TencentOpenAPI.framework),Demo中也没有找到.
接下来具体实现:
导入库:
添加SDK依赖的系统库文件。分别是“Security.framework”,“libiconv.dylib”,“SystemConfiguration.framework”,“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”
添加URL Types URL_Schemes = tencent+appid
发现配置完方法后不走回调.主要有一下两点,
1.添加白名单
LSApplicationQueriesSchemes <string>mqqstring> <string>mqqapistring> <string>mqqwpastring> <string>mqqbrowserstring> <string>mttbrowserstring> <string>mqqOpensdkSSoLoginstring> <string>mqqopensdkapiV2string> <string>mqqopensdkapiV3string> <string>mqqopensdkapiV4string> <string>wtloginmqq2string> <string>mqzonestring> <string>mqzoneopensdkstring> <string>mqzoneopensdkapistring> <string>mqzoneopensdkapi19string> <string>mqzoneopensdkapiV2string> <string>mqqapiwalletstring> <string>mqqopensdkfriendstring> <string>mqqopensdkdatalinestring> <string>mqqgamebindinggroupstring> <string>mqqopensdkgrouptribesharestring> <string>tencentapi.qq.reqContentstring> <string>tencentapi.qzone.reqContentstring>
2 回调后的设置
AppDelegate.m 中引入(最好设置成全局的,登录时还要用到)
#import#import -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([url.host isEqualToString:@"qzapp"]) { [QQApiInterface handleOpenURL:url delegate:(id )[QQApiNewsObject class]]; return [TencentOAuth HandleOpenURL:url]; } return YES; }
登录VC 中实现
引入代理方法: TencentSessionDelegate
//声明变量 @property (nonatomic,strong) TencentOAuth * tencentOAuth;
//判断是否装QQ - (void)lookQQAuth { self.tencentOAuth = [[TencentOAuth alloc]initWithAppId:@"AppId" andDelegate:self]; BOOL isInstallQQ = [TencentOAuth iphoneQQInstalled]; if (isInstallQQ == NO) { [self.qqLogin setHidden:YES]; } } //登录函数: - (void)qqLoginBtnAction { NSString *appid = TencentAppid; _tencentOAuth = [[TencentOAuth alloc] initWithAppId:appid andDelegate:self]; NSMutableArray * permission = [NSMutableArray arrayWithObjects:@[kOPEN_PERMISSION_GET_INFO, kOPEN_PERMISSION_GET_USER_INFO, kOPEN_PERMISSION_GET_SIMPLE_USER_INFO],nil]; [_tencentOAuth authorize:permission inSafari:NO]; } #pragma mark --------- qq登录状态回调 TencentSessionDelegate------ //登录成功: - (void)tencentDidLogin { if (_tencentOAuth.accessToken.length > 0) { // 获取用户信息 [_tencentOAuth getUserInfo]; [_qqInfoDict setValue:_tencentOAuth.openId forKey:@"openid"]; } else { NSLog(@"登录不成功 没有获取accesstoken"); } } //非网络错误导致登录失败: - (void)tencentDidNotLogin:(BOOL)cancelled { if (cancelled) { NSLog(@"用户取消登录"); } else { NSLog(@"登录失败"); } } - (void)tencentDidNotNetWork { NSLog(@"检查网络"); } // 获取用户信息 - (void)getUserInfoResponse:(APIResponse *)response { if (response && response.retCode == URLREQUEST_SUCCEED) { // 字符串 转字典 取用户信息 NSDictionary *userInfo = [NSString dictionaryWithJsonString:response.message]; // 开始登录(请求服务器) [self qqLoginRequest]; } else { NSLog(@"QQ auth fail ,getUserInfoResponse:%d", response.detailRetCode); } }