#import "ViewController.h"
#import <Social/Social.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//1、判断平台是否可用
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
NSLog(@"平台不可用,或者没有配置相关账号");
return;
}
//2.0 创建分享的控制器
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
//2.1 添加分享的文字
[composeVC setInitialText:@"今天天气真好!"];
//2.2 添加一个图片
[composeVC addImage:[UIImage imageNamed:@"1"]];
//2.3 添加一个分享的链接
[composeVC addURL:[NSURL URLWithString:@"www.nice.com"]];
//3 弹出分享控制器
[self presentViewController:composeVC animated:YES completion:nil];
//4 监听用户点击了取消还是发送
composeVC.completionHandler = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"点击了取消");
} else {
NSLog(@"点击了发送");
}
};
}
@end
本文介绍如何使用Social框架在iOS应用中实现新浪微博分享功能,包括检查平台可用性、创建分享视图控制器并设置分享内容等步骤。

被折叠的 条评论
为什么被折叠?



