分享 - Social.framework
/**
* 第三方分享
*
* @param void 友盟分享
* @param shareSDK
* @param 百度分享
*/
#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1. 判断服务是否可用
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
LogRed(@"SLServiceTypeSinaWeibo -- 分享可用");
}
// 2. 创建分享控制器
SLComposeViewController *composeCon = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 设置默认数据
[composeCon setInitialText:@"今天天气很好"];
[composeCon addImage:[UIImage imageNamed:@"1.jpg"]];
// 3. 弹出分享控制器
[self presentViewController:composeCon animated:YES completion:nil];
// 4. 监听分享状态
composeCon.completionHandler = ^(SLComposeViewControllerResult result){
/**
*
SLComposeViewControllerResultCancelled,
SLComposeViewControllerResultDone
*/
if (result == SLComposeViewControllerResultCancelled){
LogRed(@"取消发送");
}else if(result == SLComposeViewControllerResultDone){
LogRed(@"发送成功");
}
};
}