本文執行個體為大家分享了iOS QQ第三方登入實現代碼,供大家參考,具體內容如下
一、準備工作
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]; } [objc] view plain copy 在CODE上查看代碼片派生到My Code片- (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"]; }
以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。