添加友盟SDK,实现新浪分享和微信朋友圈分享的关键代码

//直接分享内容到新浪 ,不用弹出编辑界面

[[UMSocialDataService defaultDataService] setSocialData:[UMSocialData defaultData]];

    UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:

                                        _detailModel.productInfo.imageUrl];

    UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_detailModel.productInfo.info]]];

    

    [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:[NSString stringWithFormat:@"%@%@",_detailModel.productInfo.info,_detailModel.productInfo.shareUrl] image:image location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *shareResponse){

        btn.enabled = YES;

        if (shareResponse.responseCode == UMSResponseCodeSuccess) {

            [[ActivityRemindView loadFromXib] showActivityViewInView:self.view withMsg:@"分享成功" inSeconds:1];

        }else{

            [[ActivityRemindView loadFromXib] showActivityViewInView:self.view withMsg:@"分享失败" inSeconds:1];

        }

    }];

 

 

    /*************** 带编辑页分享到到新浪 *************/

    

    

    [UMSocialConfig setFinishToastIsHidden:YES position:UMSocialiToastPositionTop];

    UMSocialData * socialData = [UMSocialData defaultData];

    socialData.urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:

                              _detailModel.productInfo.imageUrl];

    socialData.shareImage =  [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_detailModel.productInfo.info]]];

    socialData.shareText = [NSString stringWithFormat:@"%@\n%@\n",_detailModel.productInfo.info,_detailModel.productInfo.shareUrl];    

    __unsafe_unretained ProductDetailInfoController * productController = self;

    

    UMSocialControllerService * umSvc = [[UMSocialControllerService defaultControllerService] initWithUMSocialData:socialData];

    

    umSvc.socialUIDelegate = productController;

//    [[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"%@%@",_detailModel.productInfo.info,_detailModel.productInfo.shareUrl] shareImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_detailModel.productInfo.info]]] socialUIDelegate:productController];    

    //设置分享内容和回调对象

    [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);

 

 

//分享到朋友圈

[UMSocialConfig setFinishToastIsHidden:YES position:UMSocialiToastPositionTop];

    [UMSocialData defaultData].extConfig.wechatTimelineData.url = _detailModel.productInfo.shareUrl;

    UMSocialUrlResource * urlResource = [[UMSocialUrlResource allocinitWithSnsResourceType:UMSocialUrlResourceTypeImage url:_detailModel.productInfo.imageUrl];

    

    UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_detailModel.productInfo.info]]];

    

    [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:_detailModel.productInfo.info image:image location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){

        

        if (response.responseCode == UMSResponseCodeSuccess) {

            [[ActivityRemindView loadFromXibshowActivityViewInView:self.view withMsg:@"分享成功" inSeconds:1];

        }else{

            [[ActivityRemindView loadFromXibshowActivityViewInView:self.view withMsg:@"分享失败" inSeconds:1];

        }

    }];

转载于:https://www.cnblogs.com/tianlin106/p/4177331.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值