100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > iOS开发-使用ShareSDK做分享如何让新浪分享后是可点击蓝色文字

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

时间:2022-06-04 13:06:55

相关推荐

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

如图:

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

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

//1、构造分享内容//1.1、要分享的图片(以下分别是网络图片和本地图片的生成方式的示例)id<ISSCAttachment> remoteAttachment = [ShareSDKCoreService attachmentWithUrl:@"http://f./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:nilimage:remoteAttachmenttitle:@"test title"url:@""description:nilmediaType: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:nilcancelButtonTitle:@"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:containershareList:shareListcontent:publishContentstatusBarTips:NOauthOptions:nilshareOptions:nilresult:^(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:nildelegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];}else if (state == SSResponseStateFail){UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed"message:[NSString stringWithFormat:@"Error Description:%@",[error errorDescription]]delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil, nil];[alert show];}}];

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

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

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

- (void)customizePlatformShareContent:(id<ISSContent>)publishContent{//定制QQ空间分享内容[publishContent addQQSpaceUnitWithTitle:@"The title of QQ Space."url:@""site:nilfromUrl:nilcomment:@"comment"summary:@"summary"image:niltype:@(4)playUrl:nilnswb:0];//定制邮件分享内容[publishContent addMailUnitWithSubject:@"The subject of Mail"content:@"The content of Mail."isHTML:[NSNumber numberWithBool:YES]attachments:nilto:nilcc:nilbcc:nil];//定制新浪微博分享内容id<ISSCAttachment> localAttachment = [ShareSDKCoreService attachmentWithPath:[[NSBundle mainBundle] pathForResource:@"shareImg" ofType:@"png"]];[publishContent addSinaWeiboUnitWithContent:@"The content of Sina Weibo!" image:localAttachment];}

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。