您的位置:首页 > 移动开发 > IOS开发

iOSS系统分享

2016-04-25 21:41 561 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: