??昨天直接集成了QQ的最新SDK(3.2),文檔無比吐血阳堕,貌似好像很早之前寫的跋理,內(nèi)容更新,文檔卻不更新恬总。集成過程中硬是發(fā)現(xiàn)不了問題前普。不多說,直接代碼壹堰。
第一步在AppDelegate配置
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
if([url.hostisEqualToString:@"safepay"]) {
//跳轉(zhuǎn)支付寶錢包進(jìn)行支付拭卿,處理支付結(jié)果
[[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"]) {
//跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果
[[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]];
}
登錄
??一般的很多都有文檔說明贱纠,我就不多寫了峻厚,只寫關(guān)鍵。重點(diǎn)在授權(quán)之前一定要指定類型(authShareType)谆焊。不然都不知道怎么回事惠桃,就是登錄不了,這個(gè)還好有提示辖试。分享就沒有刽射。
NSArray* permissions = [NSArrayarrayWithObjects:kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,nil];
_tencentOAuth=[[TencentOAuthalloc]initWithAppId:QQAPPIDandDelegate:self];
_tencentOAuth.authShareType=AuthShareType_QQ;
//登錄操作
[_tencentOAuthauthorize:permissions];
分享
  創(chuàng)建一個(gè)新聞?lì)悓?duì)象QQApiNewsObject的時(shí)候一定要指定類型(shareDestType)。不然一樣分享不成功剃执。
self.tencentOAuth= [[TencentOAuthalloc]initWithAppId:QQAPPIDandDelegate:nil];
//申請(qǐng)一個(gè)新聞?lì)悓?duì)象
QQApiNewsObject*msgContentObj =
[QQApiNewsObjectobjectWithURL:[NSURLURLWithString:urlStr]
title:title
description:description
previewImageData:imageData];
msgContentObj.shareDestType=ShareDestTypeQQ;
//從contentObj中傳入數(shù)據(jù)誓禁,生成一個(gè)QQReq
SendMessageToQQReq*req = [SendMessageToQQReq
reqWithContent:msgContentObj];
//向QQ發(fā)送消息,查看是否可以發(fā)送
[QQApiInterfacesendReq:req];