import “ViewController.h”
import
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1.判斷平台是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"平台不可用,或者沒有配置相關的帳号");
return;
}
// 2.建立分享的控制器
SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 2.1.添加分享的文字
[composeVc setInitialText:@"會計師法制科"];
// 2.2.添加一個圖檔
[composeVc addImage:[UIImage imageNamed:@"x阿達g"]];
// 2.3.添加一個分享的連結
[composeVc addURL:[NSURL URLWithString:@"www.it.com"]];
// 3.彈出分享控制器
[self presentViewController:composeVc animated:YES completion:nil];
// 4.監聽使用者點選了取消還是發送
composeVc.completionHandler = ^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"點選了取消");
} else {
NSLog(@"點選了發送");
}
};
}
@end