cocopods導(dǎo)入第三方
pod 'TencentOpenApiSDK'
#QQ導(dǎo)入的
AppDelegate.h中
#import <TencentOpenAPI/TencentOAuth.h>
@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);
// 后續(xù)操作...
} else {
NSLog(@"QQ auth fail ,getUserInfoResponse:%d", response.detailRetCode);
}
}
//非網(wǎng)絡(luò)錯(cuò)誤導(dǎo)致登錄失敗:
- (void)tencentDidNotLogin:(BOOL)cancelled {
if (cancelled) {
NSLog(@"用戶取消登錄");
} else {
NSLog(@"登錄失敗");
}
}
- (void)tencentDidNotNetWork {
NSLog(@"網(wǎng)絡(luò)錯(cuò)誤");
}
#import <TencentOpenAPI/TencentOAuth.h>
(ViewController中)
///QQ登錄
- (IBAction)QQLogin:(id)sender {
///qq注冊(cè)
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];
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。