当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS QQ第三方登录实现

iOS QQ第三方登录实现

2019年07月24日  | 移动技术网IT编程  | 我要评论

死神543话,梅州二手房网,黄毅清个人资料

本文实例为大家分享了ios qq第三方登录实现代码,供大家参考,具体内容如下

一、准备工作

1、到qq开放平台( )注册成为开发者,申请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"]; 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网