首先,先声明一点,这里的分享平台包括以下几个:
SLServiceTypeTwitter
SLServiceTypeFacebook
SLServiceTypeSinaWeibo
SLServiceTypeTencentWeibo
SLServiceTypeLinkedIn
两个是国内的,其他都是国外的;下面来说详细编码:
以新浪为例:
-(void)shareAction{
SLComposeViewController *slcom = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
//判断手机上面是否有新浪微博;
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"nonono");
return;
}
//设置分享内容;
[slcom setTitle:@"微博分享"];
//设置分享图片;
[slcom addImage:[UIImage imageNamed:@"IMG_0155"]];
//设置分享网址
[slcom addURL:[NSURL URLWithString:@"http://blog.csdn.net/yiral/article/details/49245591"]];
__block SLComposeViewController *slcomBlock = slcom;
slcom.completionHandler = ^(SLComposeViewControllerResult reult){
if (reult == SLComposeViewControllerResultDone) {
NSLog(@"OK");
}
};
[slcomBlock dismissViewControllerAnimated:YES completion:nil];
}