作品链接:
//www.greatytc.com/users/1e0f5e6f73f6/top_articles
1.导入框架
#import <Social/Social.h>
2.代码
// 1.判断平台是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"平台不可用,请到设置界面设置相关平台的账号");
return;
}
// 2.创建分享控制器
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 2.1 添加用户分享的文字
[composeVC setInitialText:@"好山好水好地方"];
// 2.2添加用户分享的图片
[composeVC addImage:[UIImage imageNamed:@"1"]];
// 3.弹出控制器
[self presentViewController:composeVC animated:YES completion:nil];
// 4.监听用户的点击
composeVC.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"用户点击了取消按钮");
} else {
NSLog(@"发布");
}
};