本文实例为大家分享了iOS QQ第三方登录实现代码,供大家参考,具体内容如下
一、准备工作
1、到QQ开放平台(http://connect.qq.com/ )注册成为开发者,申请appkey,
2、在URL Types中添加QQ的AppID,其格式为:”tencent” + AppID 例如tencent1104463316
二、配置AppDelegate.m
1、导入<TencentOpenAPI/QQApiInterface.h> 和<TencentOpenAPI/TencentOAuth.h>两个头文件
2、配置函数:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [TencentOAuth HandleOpenURL:url]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [TencentOAuth HandleOpenURL:url]; }
三、在登录界面中设置代码
1、导入#import <TencentOpenAPI/TencentOAuth.h>
2、遵守协议:<TencentSessionDelegate>
3、触发登陆方法中写入一下代码:
-(void)QQLogin { NSArray* permissions = [NSArray arrayWithObjects: kOPEN_PERMISSION_GET_USER_INFO, kOPEN_PERMISSION_GET_SIMPLE_USER_INFO, kOPEN_PERMISSION_ADD_ALBUM, nil nil]; [self.tencentOAuth authorize:permissions]; }
4、获取用户信息
-(void)tencentDidLogin { [self.tencentOAuth getUserInfo]; } [objc] view plain copy 在CODE上查看代码片派生到我的代码片- (void)getUserInfoResponse:(APIResponse*) response { NSLog(@"getUserInfo = %@",response.jsonResponse); NSLog(@"getUserInfo.nickName = %@",[response.jsonResponseobjectForKey:@"nickname"]); NSString* alertMessage = [NSStringstringWithFormat:@"%@",response.jsonResponse]; NSString* headerPath = [response.jsonResponseobjectForKey:@"figureurl_qq_2"]; NSString* name = [response.jsonResponseobjectForKey:@"nickname"]; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。
新闻热点
疑难解答