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

iOS Social(社会化分享)

2018-03-27 10:53 211 查看

1. 导包

#import <Social/Social.h>

2. 绑定账号

1). 系统语言要切换为中文。切换方法:Settings->General->Language & Region->iPhone Language->简体中文->Done->Change to Simplified Chinese.

2). 新浪微博账号绑定。绑定方法:设置->新浪微博,输入账号和密码,点击登录即可成功绑定。

图1.png

3. 代码

#import "ViewController.h"
#import <Social/Social.h>@implementation ViewController
// 触摸屏幕分享
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// 1. 判断系统服务是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"请先到设置中打开新浪微博并配置账号");
return;
}

// 2. 创建分享控制器
SLComposeViewController *compose = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 2.1 设置文字
[compose setInitialText:@"世界上一共有10种人,一种是懂二进制的,一种是不懂二进制的."];
// 2.2 设置图片
[compose addImage:[UIImage imageNamed:@"qq"]];
// 2.3 设置网址
[compose addURL:[NSURL URLWithString:@"https://www.jianshu.com/u/5d2cb4bfeb15"]];

// 3. 模态弹出
[self presentViewController:compose animated:YES completion:nil];
}

@end


图2.png
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: