如图:
要想实现新浪分享是这种形式,首先分享内容里要包含链接,而不能直接放在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中是有的,可以自己去看看,要是实在找不到,请给博主留言。