iOS QQ第三方授权登录(cocoa pods)

cocoa pods集成
(写一句代码都是罪过)
腾讯开发品台
创建一个项目(做demo不需要提交审核)
info -> URL Types 设置回调 URL Schemes
identifier: tencentopenapi
URL: Schemes tencentAPPID

iOS QQ第三方授权登录(cocoa pods)_第1张图片
WechatIMG1.jpeg

设置白名单(QQ全面的白名单)

LSApplicationQueriesSchemes
 
  mqqapi
  mqq
  mqqOpensdkSSoLogin
  mqqconnect
  mqqopensdkdataline
  mqqopensdkgrouptribeshare
  mqqopensdkfriend
  mqqopensdkapi
  mqqopensdkapiV2
  mqqopensdkapiV3
  mqzoneopensdk
  mqqopensdkapiV3
  mqqopensdkapiV3
  mqzone
  mqzonev2
  mqzoneshare
  wtloginqzone
  mqzonewx
  mqzoneopensdkapiV2
  mqzoneopensdkapi19
  mqzoneopensdkapi
  mqzoneopensdk
 

设置ATS

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
#import "AppDelegate.h"
#import 

@interface AppDelegate ()
///TencentOAuth *tencentOAuth
@property(nonatomic,strong)TencentOAuth *tencentOAuth;
@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"1105767298" andDelegate:self];
    NSArray *permissions = [NSArray arrayWithObjects:kOPEN_PERMISSION_GET_INFO, kOPEN_PERMISSION_GET_USER_INFO, kOPEN_PERMISSION_GET_SIMPLE_USER_INFO, nil];

    [_tencentOAuth authorize:permissions];

    return YES;
}
//登录成功:
- (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(@"登录失败");
    }
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
    return [TencentOAuth HandleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [TencentOAuth HandleOpenURL:url];
}
@end

你可能感兴趣的:(iOS QQ第三方授权登录(cocoa pods))