#import <Social/Social.h> @interface HMViewController () @end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad];
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 新浪微博服务不可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) return; // 1.创建分享控制器
SLComposeViewController *cvv = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 设置初始化数据
[cvv setInitialText:@"郭XX xx xx -- 新闻链接:http://www.baidu.com/news/5435345"];
[cvv addImage:[UIImage imageNamed:@"lufy"]]; // 2.显示控制器
[self presentViewController:cvv animated:YES completion:nil]; // 3.设置block监听
cvv.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"取消发送");
} else {
NSLog(@"发送完毕");
}
};
} @end