1.下载QQ官方API文档,导入对应的包
2.在Info->URL Types文件添加
Identifier:tencent URL Schemes:tencent+应用appkey(去腾讯后台注册)
3.Appdelegate文件
#pragma mark --- QQLogin----- - (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]; }
4.对应的viewController文件
#import <TencentOpenAPI/TencentOAuth.h> @interface LoginController ()<TencentSessionDelegate> { UIView *_loginView; TencentOAuth *_tencentLogin; } //QQ -(void)qqLogin:(UIButton *)btn { _tencentLogin=[[TencentOAuth alloc]initWithAppId:@"222222" andDelegate:self]; NSArray *permissions = [NSArray arrayWithObjects:@"get_user_info", @"get_simple_userinfo", @"add_t", nil]; [_tencentLogin authorize:permissions localAppId:@"222222" inSafari:YES]; } #pragma mark----QQLogin---- -(void)tencentDidLogin { NSString *infoUrl=[NSString stringWithFormat:@"https://graph.qq.com/user/get_simple_userinfo?access_token=%@&oauth_consumer_key=%@&openid=%@",_tencentLogin.accessToken,@"222222",_tencentLogin.openId]; //NSLog(@"%@",infoUrl); [NetWorkManage getUserInfoByQQWithUrl:infoUrl whenSuccess:^(id responseData) { id result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil]; if ([result isKindOfClass:[NSDictionary class]]) { NSDictionary *userDic = result; // NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:userDic[@"figureurl_qq_2"]]]; [userDefault setObject:userDic[@"nickname"] forKey:@"NickName"]; [userDefault setObject:data forKey:@"UserImg"]; [userDefault synchronize]; self.showUserData(); [self.navigationController popViewControllerAnimated:YES]; } } Failure:^(NSError *error) { }]; } -(void)tencentDidNotNetWork { } -(void)tencentDidNotLogin:(BOOL)cancelled { }