IOS开发之qq分享原生接入SDK

写在正文之前:腾讯的qq SDK是真的坑!这个文档简直是我见过最坑的文档了!被逼着接原生SDK做分享的我只能自己去填坑了!!!

简单来说,主要分为以下几个步骤:

一、首先,把TencentOpenAPI.framework导入工程中。

二、添加SDK依赖的系统库文件

“Security.framework”、“libiconv.dylib”、“SystemConfiguration.framework”、“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”。

三、在AppDelegate.h中 导入 头文件

#import 

四、注册分享功能

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[[TencentOAuth alloc] initWithAppId:TencentAppId andDelegate:nil]; 

}

五、在AppDelegate 的handleOpenURL和openURL方法中添加关于qq分享的相关处理

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    NSString *string =[url absoluteString];
    if ([string hasPrefix:JBSWeixinAppId]){
        return [WXApi handleOpenURL:url delegate:self];
    }else if ([string hasPrefix:TencentAppId]){
        return[TencentOAuth HandleOpenURL:url];
    }
    return NO;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
    NSString *string =[url absoluteString];
     if ([string hasPrefix:JBSWeixinAppId]){
        return [WXApi handleOpenURL:url delegate:self];
    }else if ([string hasPrefix:TencentAppId]){
        return[TencentOAuth HandleOpenURL:url];
    }
    return NO;
}

(注意:这里不用实现TencentSessionDelegate代理方法,因为手机QQ里分享时,会等到分享成功后,才会跳回原应用,所以不用监听发送情况)

六、在ViewCotroller里加入头文件

#import  
#import 
#import 

七、发起qq分享

-(void)tencentShare{

if (![TencentOAuth iphoneQQInstalled]) {
           [self showAlert:@"检查到您没有安装腾讯QQ,请先安装QQ再分享。"];
        }else {
            NSURL *newsUrl = [NSURL URLWithString:[self.shareData.link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            self.tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"123456"
                                                        andDelegate:self];
            QQApiNewsObject *newsObj = [QQApiNewsObject
                                        objectWithURL:newsUrl
                                        title:self.shareData.title
                                        description:self.shareData.desc
                                        previewImageURL:[NSURL URLWithString:self.shareData.imgUrl]];
            SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
            if (btn.tag == 0) {
                NSLog(@"QQ好友列表分享 ");
            }else if (btn.tag == 1){
                NSLog(@"QQ空间分享 ");
            }
        }
}

然后,运行起来,搞定~
(最后再吐槽一波官方qq 分享的文档,是真滴坑)

你可能感兴趣的:(IOS开发之qq分享原生接入SDK)