iOS开发-使用ShareSDK做分享如何让新浪分享后是可点击蓝色文字

如图:图是盗用别人的哈

要想实现新浪分享是这种形式,首先分享内容里要包含链接,而不能直接放在url里面,分享的type必须是SSPublishContentMediaTypeNews

下面看如何来单独自定义新浪的分享:

   //1、构造分享内容
    //1.1、要分享的图片(以下分别是网络图片和本地图片的生成方式的示例)
    id<ISSCAttachment> remoteAttachment = [ShareSDKCoreService attachmentWithUrl:@"http://f.hiphotos.bdimg.com/album/w%3D2048/sign=df8f1fe50dd79123e0e09374990c5882/cf1b9d16fdfaaf51e6d1ce528d5494eef01f7a28.jpg"];
//    id<ISSCAttachment> localAttachment = [ShareSDKCoreService attachmentWithPath:[[NSBundle mainBundle] pathForResource:@"shareImg" ofType:@"png"]];

    //1.2、以下参数分别对应:内容、默认内容、图片、标题、链接、描述、分享类型
    id<ISSContent> publishContent = [ShareSDK content:@"Test content of ShareSDK"
                                       defaultContent:nil
                                                image:remoteAttachment
                                                title:@"test title"
                                                  url:@"http://www.mob.com"
                                          description:nil
                                            mediaType:SSPublishContentMediaTypeNews];

    //1.3、自定义各个平台的分享内容(非必要)
    [self customizePlatformShareContent:publishContent];

    //1.4、自定义一个分享菜单项(非必要)
    id<ISSShareActionSheetItem> customItem = [ShareSDK shareActionSheetItemWithTitle:@"Custom"
                                                                                icon:[UIImage imageNamed:@"Icon.png"]
                                                                        clickHandler:^{
                                                                            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom item"
                                                                                                                                message:@"Custom item has been clicked"
                                                                                                                               delegate:nil
                                                                                                                      cancelButtonTitle:@"OK"
                                                                                                                      otherButtonTitles:nil];
                                                                            [alertView show];
                                                                        }];
    //1.5、分享菜单栏选项排列位置和数组元素index相关(非必要)
    NSArray *shareList = [ShareSDK customShareListWithType:
                          SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
                          SHARE_TYPE_NUMBER(ShareTypeFacebook),
                          SHARE_TYPE_NUMBER(ShareTypeWeixiSession),
                          SHARE_TYPE_NUMBER(ShareTypeWeixiTimeline),
                          SHARE_TYPE_NUMBER(ShareTypeSMS),
                          SHARE_TYPE_NUMBER(ShareTypeQQ),
                          SHARE_TYPE_NUMBER(ShareTypeQQSpace),
                          SHARE_TYPE_NUMBER(ShareTypeMail),
                          SHARE_TYPE_NUMBER(ShareTypeCopy),
                          customItem,nil];

    //1+、创建弹出菜单容器(iPad应用必要,iPhone应用非必要)
    id<ISSContainer> container = [ShareSDK container];
    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];

    //2、展现分享菜单
    [ShareSDK showShareActionSheet:container
                         shareList:shareList
                           content:publishContent
                     statusBarTips:NO
                       authOptions:nil
                      shareOptions:nil
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {

                                NSLog(@"=== response state :%zi ",state);

                                //可以根据回调提示用户。
                                if (state == SSResponseStateSuccess)
                                {
                                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                                                                    message:nil
                                                                                   delegate:self
                                                                          cancelButtonTitle:@"OK"
                                                                          otherButtonTitles:nil, nil];
                                    [alert show];
                                }
                                else if (state == SSResponseStateFail)
                                {
                                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed"
                                                                                    message:[NSString stringWithFormat:@"Error Description:%@",[error errorDescription]]
                                                                                   delegate:self
                                                                          cancelButtonTitle:@"OK"
                                                                          otherButtonTitles:nil, nil];
                                    [alert show];
                                }
                            }];

以上是一个完整的分享,看清楚啦,是自定义分享:

//这行代码是关键
    [self customizePlatformShareContent:publishContent];

看一下这个方法调用是如何实现的,怎么实现的新浪分享内容自定义:

- (void)customizePlatformShareContent:(id<ISSContent>)publishContent
{
    //定制QQ空间分享内容
    [publishContent addQQSpaceUnitWithTitle:@"The title of QQ Space."
                                        url:@"http://www.mob.com"
                                       site:nil
                                    fromUrl:nil
                                    comment:@"comment"
                                    summary:@"summary"
                                      image:nil
                                       type:@(4)
                                    playUrl:nil
                                       nswb:0];

    //定制邮件分享内容
    [publishContent addMailUnitWithSubject:@"The subject of Mail"
                                   content:@"The content of Mail."
                                    isHTML:[NSNumber numberWithBool:YES]
                               attachments:nil
                                        to:nil
                                        cc:nil
                                       bcc:nil];
    //定制新浪微博分享内容
    id<ISSCAttachment> localAttachment = [ShareSDKCoreService attachmentWithPath:[[NSBundle mainBundle] pathForResource:@"shareImg" ofType:@"png"]];
    [publishContent addSinaWeiboUnitWithContent:@"The content of Sina Weibo!http://www.baidu.com" image:localAttachment];
}

不只是新浪微博,别的平台也是可以自定义分享方式的,对于新浪,要实现如上图中的那种形式,需要把链接放在分享内容中,其他的平台则是正常的常规方式。不再放Demo上去,其实这个方法在ShareSDK中是有的,可以自己去看看,要是实在找不到,请给博主留言。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodingFire

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值