#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 不能再viewDidLoad进行模态视图的弹出
//Warning: Attempt to present <SLComposeViewController: 0x7f9fcb823180> on <ViewController: 0x7f9fca6a1b60> whose view is not in the window hierarchy!
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//1. 判断分享类型是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"请先到设置中添加新浪微博账号");
return;
}
//2. 创建分享控制器
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 设置预设值
//2.1 文字
//二进制 1 10
[composeVC setInitialText:@"这个世界上有10种人, 一种是懂二进制的, 一种是不懂二进制的"];
//2.2 图片
[composeVC addImage:[UIImage imageNamed:@"dog"]];
//2.3 网址
[composeVC addURL:[NSURL URLWithString:@"https://www.baidu.com"]];
//3. 弹出分享控制器
[self presentViewController:composeVC animated:YES completion:nil];
}
@end