导入系统库 StoreKit.framework
#import <Social/Social.h>
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// 首先判断新浪分享是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"未安装客户端");
return;
}
// 创建控制器,并设置ServiceType
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 添加要分享的图片
[composeVC addImage:[UIImage imageNamed:@"1"]];
// 添加要分享的文字
[composeVC setInitialText:@"share my CSDN Blog"];
// 添加要分享的url
[composeVC addURL:[NSURL URLWithString:@"http://blog.csdn.net/u011058732"]];
// 弹出分享控制器
[self presentViewController:composeVC animated:YES completion:nil];
// 监听用户点击事件
composeVC.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
NSLog(@"点击了发送");
}
else if (result == SLComposeViewControllerResultCancelled)
{
NSLog(@"点击了取消");
}
};
}