iOS Social(社会化分享)

1. 导包
#import <Social/Social.h>
2. 绑定账号

1). 系统语言要切换为中文。切换方法:Settings->General->Language & Region->iPhone Language->简体中文->Done->Change to Simplified Chinese.
2). 新浪微博账号绑定。绑定方法:设置->新浪微博,输入账号和密码,点击登录即可成功绑定。


3110861-a68c3ca84444658f.png
图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
3110861-7e7d6a06f45c5b1a.png
图2.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值