1.導(dǎo)入頭文件
#import <Social/Social.h>
2.演示效果,點(diǎn)擊屏幕的時(shí)候,彈出分享(新浪微博)
// 點(diǎn)擊屏幕,分享到新浪微博
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 1.創(chuàng)建控制器
SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 2.modal展示
[self presentViewController:composeVc animated:YES completion:nil];
}

default.png
系統(tǒng)提供的分享方式比較少,serviceType:
NSString *const SLServiceTypeFacebook;
NSString *const SLServiceTypeTwitter;
NSString *const SLServiceTypeSinaWeibo;
NSString *const SLServiceTypeTencentWeibo;
使用系統(tǒng)分享功能控制臺(tái)可能會(huì)出現(xiàn)提示:plugin com.apple.share.SinaWeibo.post invalidated,忽略即可
還可以設(shè)置缺省文字、圖片和Url:
// 2.1 設(shè)置圖片
[composeVc addImage:[UIImage imageNamed:@"girl"]];
// 2.2 設(shè)置Url
[composeVc addURL:[NSURL URLWithString:@"http://www.itdecent.cn/users/5ec5747435a2/latest_articles"]];
// 2.3 設(shè)置缺省文字
[composeVc setInitialText:@"InitialText:"];
效果:

set_properties.png
完整演示代碼:
#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// 點(diǎn)擊屏幕,分享到新浪微博
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 1.創(chuàng)建控制器
SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 2.設(shè)置屬性
// 2.1 設(shè)置圖片
[composeVc addImage:[UIImage imageNamed:@"girl"]];
// 2.2 設(shè)置Url
[composeVc addURL:[NSURL URLWithString:@"http://www.itdecent.cn/users/5ec5747435a2/latest_articles"]];
// 2.3 設(shè)置缺省文字
[composeVc setInitialText:@"InitialText:"];
// 3.modal展示
[self presentViewController:composeVc animated:YES completion:nil];
}