QQ分享以及登錄(iOS)巨坑

??昨天直接集成了QQ的最新SDK(3.2),文檔無比吐血,貌似好像很早之前寫的,內容更新,文檔卻不更新。集成過程中硬是發(fā)現不了問題。不多說,直接代碼。

第一步在AppDelegate配置

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation

{

if([url.hostisEqualToString:@"safepay"]) {

//跳轉支付寶錢包進行支付,處理支付結果

[[AlipaySDKdefaultService]processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary*resultDic) {

NSLog(@"result = %@",resultDic);

}];

returnYES;

}

if([url.absoluteStringhasPrefix:[NSStringstringWithFormat:@"tencent%@",QQAPPID]]) {

if([TencentOAuthCanHandleOpenURL:url]) {

return[TencentOAuthHandleOpenURL:url];

}else

{

return[QQApiInterfacehandleOpenURL:urldelegate:[QQApiManagersharedManager]];

}

}

return[WXApihandleOpenURL:urldelegate:[WXApiManagersharedManager]];

}

- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary *)options

{

if([url.hostisEqualToString:@"safepay"]) {

//跳轉支付寶錢包進行支付,處理支付結果

[[AlipaySDKdefaultService]processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary*resultDic) {

NSLog(@"result = %@",resultDic);

}];

returnYES;

}

if([url.absoluteStringhasPrefix:[NSStringstringWithFormat:@"tencent%@",QQAPPID]]) {

if([TencentOAuthCanHandleOpenURL:url]) {

return[TencentOAuthHandleOpenURL:url];

}else

{

return[QQApiInterfacehandleOpenURL:urldelegate:[QQApiManagersharedManager]];

}

}

return[WXApihandleOpenURL:urldelegate:[WXApiManagersharedManager]];

}

登錄

??一般的很多都有文檔說明,我就不多寫了,只寫關鍵。重點在授權之前一定要指定類型(authShareType)。不然都不知道怎么回事,就是登錄不了,這個還好有提示。分享就沒有。

NSArray* permissions = [NSArrayarrayWithObjects:kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,nil];

_tencentOAuth=[[TencentOAuthalloc]initWithAppId:QQAPPIDandDelegate:self];

_tencentOAuth.authShareType=AuthShareType_QQ;

//登錄操作

[_tencentOAuthauthorize:permissions];

分享

  創(chuàng)建一個新聞類對象QQApiNewsObject的時候一定要指定類型(shareDestType)。不然一樣分享不成功。

self.tencentOAuth= [[TencentOAuthalloc]initWithAppId:QQAPPIDandDelegate:nil];

//申請一個新聞類對象

QQApiNewsObject*msgContentObj =

[QQApiNewsObjectobjectWithURL:[NSURLURLWithString:urlStr]

title:title

description:description

previewImageData:imageData];

msgContentObj.shareDestType=ShareDestTypeQQ;

//從contentObj中傳入數據,生成一個QQReq

SendMessageToQQReq*req = [SendMessageToQQReq

reqWithContent:msgContentObj];

//向QQ發(fā)送消息,查看是否可以發(fā)送

[QQApiInterfacesendReq:req];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容