iOS QQ第三方登錄實現(xiàn)
本文實例為大家分享了iOS QQ第三方登錄實現(xiàn)代碼,供大家參考,具體內(nèi)容如下
一、準(zhǔn)備工作
1、到QQ開放平臺(http://connect.qq.com/ )注冊成為開發(fā)者,申請appkey,
2、在URL Types中添加QQ的AppID,其格式為:”tencent” + AppID 例如tencent1104463316
二、配置AppDelegate.m
1、導(dǎo)入<TencentOpenAPI/QQApiInterface.h> 和<TencentOpenAPI/TencentOAuth.h>兩個頭文件
2、配置函數(shù):
- (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]; }
三、在登錄界面中設(shè)置代碼
1、導(dǎo)入#import <TencentOpenAPI/TencentOAuth.h>
2、遵守協(xié)議:<TencentSessionDelegate>
3、觸發(fā)登陸方法中寫入一下代碼:
-(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上查看代碼片派生到我的代碼片 - (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"]; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS自定義collectionView實現(xiàn)毛玻璃效果
不知道大家發(fā)現(xiàn)沒有蘋果在iOS7.0之后,很多系統(tǒng)界面都使用了毛玻璃效果,增加了界面的美觀性,所以這篇文章跟大家分享個iOS自定義collectionView實現(xiàn)毛玻璃效果的方法,有需要的可以參考借鑒,下面來一起看看。2016-09-09IOS 圖文混排(CoreText.framework)詳解及實例
這篇文章主要介紹了IOS 圖文混排(CoreText.framework)詳解及實例的相關(guān)資料,這里對IOS 的圖文混排進(jìn)行了詳細(xì)介紹,并附代碼實例,和實現(xiàn)效果圖,需要的朋友可以參考下2016-11-11IOS 出現(xiàn)錯誤reason: image not found的解決方案
這篇文章主要介紹了IOS 出現(xiàn)錯誤reason: image not found的解決方案的相關(guān)資料,需要的朋友可以參考下2017-05-05