昨天直接集成了QQ的最新SDK(3.2),文档无比吐血,貌似好像很早之前写的,内容更新,文档却不更新。集成过程中硬是发现不了问题。不多说,直接代码。
第一步在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];
分享
  创建一个新闻类对象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发送消息,查看是否可以发送
[QQApiInterfacesendReq:req];