1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
2 {
3 // 1.判斷平台是否可用
4 if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
5 NSLog(@"平台不可用,或者沒有配置相關的帳號");
6 return;
7 }
8
9 // 2.創建分享的控制器
10 SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
11
12 // 2.1.添加分享的文字
13 [composeVc setInitialText:@"我是一個codeMan"];
14
15 // 2.2.添加一個圖片
16 [composeVc addImage:[UIImage imageNamed:@"xingxing"]];
17
18 // 2.3.添加一個分享的鏈接
19 [composeVc addURL:[NSURL URLWithString:@"www.baidu.com"]];
20
21 // 3.彈出分享控制器
22 [self presentViewController:composeVc animated:YES completion:nil];
23
24 // 4.監聽用戶點擊了取消還是發送
25 composeVc.completionHandler = ^(SLComposeViewControllerResult result) {
26 if (result == SLComposeViewControllerResultCancelled) {
27 NSLog(@"點擊了取消");
28 } else {
29 NSLog(@"點擊了發送");
30 }
31 };
32 }