1.首先導入Social/Social.h框架,然後執行以下代碼:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"分享可用");
}
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
[vc setInitialText:@"hahahaha"];
//可以添加圖片
// [vc addImage:[UIImage imageNamed:@""]];
[self presentViewController:vc animated:YES completion:nil];
vc.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"quxiao");
}else{
NSLog(@"wancheng");
}
};
}