码迷,mamicode.com
首页 > 其他好文 > 详细

集成友盟SDK后,实现自定义分享的关键代码

时间:2014-12-22 00:52:50      阅读:474      评论:0      收藏:0      [点我收藏+]

标签:

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

[[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 alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:_detailModel.productInfo.imageUrl];

    

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

    

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

        

        if (response.responseCode == UMSResponseCodeSuccess) {

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

        }else{

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

        }

    }];

集成友盟SDK后,实现自定义分享的关键代码

标签:

原文地址:http://www.cnblogs.com/tianlin106/p/4177331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!