iOS 分享到qq好友,qq空间,微信好友,微信朋友圈,新浪微博
iOS 分享到qq好友,qq空间,微信好友,微信朋友圈,新浪微博
山里来的 发表于2年前
iOS 分享到qq好友,qq空间,微信好友,微信朋友圈,新浪微博
  • 发表于 2年前
  • 阅读 28
  • 收藏 0
  • 点赞 2
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

都是单独的分享功能 没有使用shareSdk,mob等第三方

首先你都必须要在appdelegate注册key

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];   [self tabBarController];
    //微信
    [WXApi registerApp:WX_key]; 
    //腾讯
    _tencentOAuth = [[TencentOAuth alloc]initWithAppId:QQ_key andDelegate:self];
    //微博
    [WeiboSDK registerApp:WB_key];
    
    return YES;
}
// 处理回调

- (BOOL)application:(UIApplication *)application handleOpenURL:(nonnull NSURL *)url{
    
    if (YES == [TencentApiInterface handleOpenURL:url delegate:self])
    {
      return  [TencentApiInterface handleOpenURL:url delegate:self];
    }
    
    if (YES == [WXApi handleOpenURL:url delegate:self])
    {
        return [WXApi handleOpenURL:url delegate:self];
    }
    
    if ([WeiboSDK handleOpenURL:url delegate:self]) {
        return [WeiboSDK handleOpenURL:url delegate:self];
    }
    return YES;


  }

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options{
    
    if (YES == [TencentApiInterface canOpenURL:url delegate:self])
    {
        return  [TencentApiInterface canOpenURL:url delegate:self];
    }
    
    if(YES == [WXApi handleOpenURL:url delegate:self]){
        return [WXApi handleOpenURL:url delegate:self];
    }
    
    if ([WeiboSDK handleOpenURL:url delegate:self]) {
        return [WeiboSDK handleOpenURL:url delegate:self];
    }
    return YES;
   
}
  1. 分享到qq (官方文档写了OAuth授权,是实现了网页版分享)
// qq好友
- (void)shareByQQFriend{
    
   NSData *imgData = UIImagePNGRepresentation([UIImage imageNamed:@"shareLog.png"]);
    QQApiImageObject *imgObj = [QQApiImageObject objectWithData:imgData
                                               previewImageData:imgData
                                                          title:@"标题"
                                                    description:@"分享描述"];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
    //将内容分享到qq
    QQApiSendResultCode sent = [QQApiInterface sendReq:req];
    [self handleSendResult:sent];
}

// qq空间
- (void)shareQQZone{

    NSString *utf8String = @"http://www.imspore.com";
    NSString *title = @"qq空间分享";
    NSString *description = @"描述";
    NSString *previewImageUrl = [_shopDetailsDic[@"productLinkAddress"] firstObject];
    QQApiNewsObject *newsObj = [QQApiNewsObject
                                objectWithURL:[NSURL URLWithString:utf8String]
                                title:title
                                description:description
                                previewImageURL:[NSURL URLWithString:previewImageUrl]];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];

    //将内容分享到qzone
    QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
    [self handleSendResult:sent];
}
  1. 分享到微信
// 发给微信好友
- (void)shareByWXfirends{

  
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = @"分享给你一个好消息";
    message.description = @"描述";
    [message setThumbImage:[UIImage imageNamed:@"shareLog.png"]];
    
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = @"http://www.imspore.com";
    
    message.mediaObject = ext;
    
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneSession;
    
    if ([WXApi sendReq:req]){
        NSLog(@"分享成功");
    }else{
        NSLog(@"分享失败");
    }
    
}

// 分享朋友圈
- (void)shareByWXCycle{
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = @"分享的标题";
    message.description = @"分享的描述";
    [message setThumbImage:[UIImage imageNamed:@"shareLog.png"]];
    
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = @"http://www.imspore.com";
    
    message.mediaObject = ext;
    
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneTimeline;//微信朋友圈
    
    [WXApi sendReq:req];

}
  1. 分享到新浪微博
- (void)shareBySinaWB{
    
    WBMessageObject *message = [WBMessageObject message];
    message.text = @"我是测试文字";
    WBImageObject *image = [WBImageObject object];
    image.imageData = UIImagePNGRepresentation([UIImage imageNamed:@"shareLog.png"]);
    message.imageObject = image;
    
    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message];
    request.userInfo = @{@"ShareMessageFrom": @"111",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    [WeiboSDK sendRequest:request];
    
}

记得要去设置 URL Scheme 记得要去设置 URL Scheme

关于iOS9 需要设置白名单 在“Info.plist”里增加如下代码

<key>LSApplicationQueriesSchemes</key>
 <array>
    <!-- 微信 URL Scheme 白名单-->
    <string>wechat</string>
    <string>weixin</string>

    <!-- 新浪微博 URL Scheme 白名单-->
    <string>sinaweibohd</string>
    <string>sinaweibo</string>
    <string>sinaweibosso</string>
    <string>weibosdk</string>
    <string>weibosdk2.5</string>

    <!-- QQ、Qzone URL Scheme 白名单-->
    <string>mqqapi</string>
    <string>mqq</string>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqqconnect</string>
    <string>mqqopensdkdataline</string>
    <string>mqqopensdkgrouptribeshare</string>
    <string>mqqopensdkfriend</string>
    <string>mqqopensdkapi</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqzoneopensdk</string>
    <string>wtloginmqq</string>
    <string>wtloginmqq2</string>
    <string>mqqwpa</string>
    <string>mqzone</string>
    <string>mqzonev2</string>
    <string>mqzoneshare</string>
    <string>wtloginqzone</string>
    <string>mqzonewx</string>
    <string>mqzoneopensdkapiV2</string>
    <string>mqzoneopensdkapi19</string>
    <string>mqzoneopensdkapi</string>
    <string>mqzoneopensdk</string>

    <!-- 支付宝  URL Scheme 白名单-->
    <string>alipay</string>
    <string>alipayshare</string>

</array>
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 8
博文 81
码字总数 16804
×
山里来的
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: