一、准备工作
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];
- }
- - (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"];
- }