在工程配置中的“Build Settings”一栏中找到“Linking”配置区,给“Other Linker Flags”配置项添加属性值“-fobjc-arc”
<key>LSApplicationQueriesSchemes</key> <array> <string>mqqapi</string> <string>mqq</string> <string>mqqOpensdkSSoLogin</string> <string>mqqconnect</string> <string>mqqopensdkdataline</string> <string>mqqopensdkgrouptribeshare</string> <string>mqqopensdkfriend</string> <string>mqqopensdkapi</string> <string>mqqopensdkapiV2</string> <string>mqqopensdkapiV3</string> <string>mqzoneopensdk</string> <string>wtloginmqq</string> <string>wtloginmqq2</string> <string>mqqwpa</string> <string>mqzone</string> <string>mqzonev2</string> <string>mqzoneshare</string> <string>wtloginqzone</string> <string>mqzonewx</string> <string>mqzoneopensdkapiV2</string> <string>mqzoneopensdkapi19</string> <string>mqzoneopensdkapi</string> <string>mqzoneopensdk</string> </array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
// // AppDelegate.m // QQLogin // // Created by 王园园 on 16/6/28. // Copyright © 2016年 Wangyuanyuan. All rights reserved. // #import "AppDelegate.h" #import <TencentOpenAPI/TencentOAuth.h> #define QQAppKey @"" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } //openURL - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ return [TencentOAuth HandleOpenURL:url]; } //handleURL - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{ return [TencentOAuth HandleOpenURL:url]; }
// // ViewController.m // QQLogin // // Created by 王园园 on 16/6/28. // Copyright © 2016年 Wangyuanyuan. All rights reserved. // #import "ViewController.h" #import <TencentOpenAPI/TencentOAuth.h> #define QQAppKey @"" @interface ViewController ()<TencentSessionDelegate> { UIButton *qqLoginBtn; TencentOAuth *tencentOAuth; NSArray *permissions; UILabel *resultLable; UILabel *tokenLable; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //创建登陆按钮 qqLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; qqLoginBtn.frame = CGRectMake(100, 50, 36, 36); [qqLoginBtn setTitle:@"qq登陆" forState:UIControlStateNormal]; [qqLoginBtn addTarget:self action:@selector(qqLoginAction) forControlEvents:UIControlEventTouchUpInside]; qqLoginBtn.backgroundColor = [UIColor cyanColor]; [self.view addSubview:qqLoginBtn]; //2,初始 lable resultLable=[[UILabel alloc]initWithFrame:CGRectMake(30, 100, 300, 36)]; tokenLable=[[UILabel alloc]initWithFrame:CGRectMake(30, 150, 300, 36)]; [self.view addSubview:resultLable]; [self.view addSubview:tokenLable]; //3,初始化TencentOAuth 对象 appid来自应用宝创建的应用, deletegate设置为self 一定记得实现代理方法 //这里的appid填写应用宝得到的id 记得修改 “TARGETS”一栏,在“info”标签栏的“URL type”添加 的“URL scheme”,新的scheme。有问题家QQ群414319235提问 tencentOAuth=[[TencentOAuth alloc]initWithAppId:QQAppKey andDelegate:self]; //4,设置需要的权限列表,此处尽量使用什么取什么。 permissions= [NSArray arrayWithObjects:@"get_user_info", @"get_simple_userinfo", @"add_t", nil]; } #pragma mark - qq登陆按钮响应方法 - (void)qqLoginAction{ NSLog(@"loginAct"); [tencentOAuth authorize:permissions inSafari:NO]; } #pragma mark -- TencentLoginDelegate //登陆完成调用 - (void)tencentDidLogin { resultLable.text = @"登录完成"; if (tencentOAuth.accessToken && 0 != [tencentOAuth.accessToken length]) { // 记录登录用户的OpenID、Token以及过期时间 tokenLable.text = tencentOAuth.accessToken; [tencentOAuth getUserInfo]; } else { tokenLable.text = @"登录不成功 没有获取accesstoken"; } } //获取用户个人信息回调 - (void)getUserInfoResponse:(APIResponse*) response{ //获取用户个人信息 NSLog(@"response = %@",response.jsonResponse); <span style="font-family: Arial, Helvetica, sans-serif;">}</span>
//非网络错误导致登录失败: -(void)tencentDidNotLogin:(BOOL)cancelled { NSLog(@"tencentDidNotLogin"); if (cancelled) { resultLable.text = @"用户取消登录"; }else{ resultLable.text = @"登录失败"; } } // 网络错误导致登录失败: -(void)tencentDidNotNetWork { NSLog(@"tencentDidNotNetWork"); resultLable.text = @"无网络连接,请设置网络"; }