分享到微信列表、朋友圈、微信小程序,分享到qq、qq空间、分享qq小程序,分享到微博

实现时依赖的sdk版本
'Weibo', '3.2.4'
spec.dependency 'TencentOpenApiSDK', '~> 3.3.6'(3.3.5开始qq小程序)
spec.dependency 'WechatOpenSDK', '1.8.5'

微信分享,分享小程序
细节根据自己需求修改哦~~~~~~

//微信注册
    [WXApi registerApp:string];
    
//  检测是否安装微信
    if (![WXApi isWXAppInstalled] || ![WXApi isWXAppSupportApi]) {
        return;
    }
     SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    if (shareType == ShareToWeChat) {
        req.scene = WXSceneSession;//对话列表
    } else {
        req.scene = WXSceneTimeline;    //  朋友圈
    }
        WXMediaMessage *message = [WXMediaMessage message];
        WXWebpageObject *page = [WXWebpageObject object];
        page.webpageUrl = url;
        // 设置缩略图
         message.thumbData = shareImageData;
        message.mediaObject = page;
        message.title =@"title";
        message.description = @"描述";
          //分享到小程序
    if(req.scene == WXSceneSession){
        WXMiniProgramObject *wxMiniObject = [WXMiniProgramObject object];
        wxMiniObject.webpageUrl =url;
        wxMiniObject.userName = @"xxx";
         wxMiniObject.path = @"xx"; 
        wxMiniObject.hdImageData = data;
#ifdef DEBUG
        wxMiniObject.miniProgramType = WXMiniProgramTypeTest;
#endif
        message.mediaObject = wxMiniObject;
    }
          req.message = message;
         [WXApi sendReq:req];

qq分享,分享qq小程序

 //qq注册
 [[TencentOAuth alloc] initWithAppId:string andDelegate:nil];
 if (![QQApiInterface isQQInstalled]) {
        return;
    }
   QQApiObject *  shareObj =  [QQApiVideoObject objectWithURL:[NSURL URLWithString:link] title:shareTitle description:@"zzz"  previewImageData:imageData];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:shareObj];
    [QQApiInterface sendReq:req];
    

//小程序 3.3.5以及之后的sdk才行
 QQApiVideoObject *videoObj = [QQApiVideoObject objectWithURL:[NSURL URLWithString:link] title:shareTitle description:@"aa"previewImageData:imageData;
        videoObj.cflag |= kQQAPICtrlFlagQQShareEnableMiniProgram;
        if (shareType == ShareToQzone) {
            //如果是发到空间还需要打开下面一句
            videoObj.cflag |= kQQAPICtrlFlagQZoneShareOnStart;
        }
        //小程序消息对象
        QQApiMiniProgramObject *miniObj = [QQApiMiniProgramObject new];
        miniObj.qqApiObject = videoObj;
        miniObj.miniAppID = miniObj.miniAppID;
        miniObj.webpageUrl = link;
        if ([str containsString:@"?"]) { //不转有的参数传不到小程序,这里需要看看
            NSArray *ary = [str componentsSeparatedByString:@"?"];
            str = [NSString stringWithFormat:@"%@?%@",ary.firstObject,[ary.lastObject URLEncodedString]];
        }
        miniObj.miniPath = str; 
#ifdef DEBUG
        miniObj.miniprogramType = MiniProgramType_Test;
#endif
        req = [SendMessageToQQReq reqWithMiniContent:miniObj];
        QQApiSendResultCode sent = [QQApiInterface sendReq:req];

分享到微博

//微博注册
    [WeiboSDK registerApp:string];
//没有安装微博
  if (![WeiboSDK isWeiboAppInstalled]) {
        return;
    }
WBWebpageObject *webPage = [WBWebpageObject object];
        webPage.title =@"dd";
        webPage.webpageUrl = url;
        webPage.description = @"aaaa";
        
        webPage.objectID = webPage.webpageUrl;
        
         webPage.thumbnailData =shareImageData
        message.mediaObject = webPage;
        message.text =@"ss";
         WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message];
    request.userInfo = @{@"SendMessageFrom" : @"SendMessageToWeiboViewController"};
     [WeiboSDK sendRequest:request];

#最后在AppDelegate实现WeiboSDKDelegate(微博代理), WXApiDelegate(微信代理), QQApiInterfaceDelegate(qq代理) 三个代理可以分别处理分享后来自微博,微信,qq终端程序的事件消息

你可能感兴趣的:(分享到微信列表、朋友圈、微信小程序,分享到qq、qq空间、分享qq小程序,分享到微博)