QQ登录

cocopods导入第三方  
pod 'TencentOpenApiSDK'
#QQ导入的
AppDelegate.h中
#import 
@property(nonatomic,strong)TencentOAuth *tencentOAuth;
AppDelegate中
@interface AppDelegate ()< TencentSessionDelegate>
@end
#pragma mark ------------QQ--------------------------
//登录成功:
- (void)tencentDidLogin
{
    if (_tencentOAuth.accessToken.length > 0) {
        // 获取用户信息
        [_tencentOAuth getUserInfo];
        NSLog(@"_accessToken==%@",_tencentOAuth.accessToken);
        
    } else {
        NSLog(@"登录不成功 没有获取accesstoken");
    }
}
// 获取用户信息
- (void)getUserInfoResponse:(APIResponse *)response {
    
    if (response && response.retCode == URLREQUEST_SUCCEED) {
        
        NSDictionary *userInfo = [response jsonResponse];
        NSString *nickName = userInfo[@"nickname"];
        NSLog(@"userInfo==%@",userInfo);
        NSLog(@"nicName==%@",nickName);
        // 后续操作...
        
        
    } else {
        NSLog(@"QQ auth fail ,getUserInfoResponse:%d", response.detailRetCode);
    }
}
//非网络错误导致登录失败:
- (void)tencentDidNotLogin:(BOOL)cancelled {
    if (cancelled) {
        NSLog(@"用户取消登录");
    } else {
        NSLog(@"登录失败");
    }
}

- (void)tencentDidNotNetWork {
    NSLog(@"网络错误");
}



#import 

(ViewController中)
    ///QQ登录 
- (IBAction)QQLogin:(id)sender {
    ///qq注册
    AppDelegate *appDeleagete = (AppDelegate *)[UIApplication sharedApplication].delegate;
    NSArray *permissions = [NSArray arrayWithObjects:kOPEN_PERMISSION_GET_INFO, kOPEN_PERMISSION_GET_USER_INFO, kOPEN_PERMISSION_GET_SIMPLE_USER_INFO, nil];
    
    [appDeleagete.tencentOAuth authorize:permissions];
    
}

你可能感兴趣的:(QQ登录)