不少APP中都带有社交分享功能,经过用户的分享,让更多地人去了解和使用这个APP,目前社交分享是移动互联网应用程序推广的最重要手段之一,国内较或的分享平台有微信,IOS6后苹果集成的新浪微博,还有IOS7后集成的腾讯微博。 在IOS中,实现社交分享能够本身编写各个平台的分享代码,但代码量较多,也能够利用IOS自带的Social.framework,更能够利用第三方的分享框架,如友盟,ShareSDK等。接下来先介绍一个系统自带的分享功能。 打开设备或模拟器的偏好设置,能够看到以下
系统须要先登陆到微博
项目中须要导入一个系统自带头文件 #import 咱们在屏幕的点击事件中来实现分享到微博html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
- (
void
)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 首先判断新浪分享是否可用
if
(![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
return
;
}
// 建立控制器,并设置ServiceType
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
// 添加要分享的图片
[composeVC addImage:[UIImage imageNamed:@
"Snip20150429_9"
]];
// 添加要分享的文字
[composeVC setInitialText:@
"share my CSDN Blog"
];
// 添加要分享的url
// 弹出分享控制器
[self presentViewController:composeVC animated:YES completion:nil];
// 监听用户点击事件
composeVC.completionHandler = ^(SLComposeViewControllerResult result){
if
(result == SLComposeViewControllerResultDone) {
NSLog(@
"点击了发送"
);
}
else
if
(result == SLComposeViewControllerResultCancelled)
{
NSLog(@
"点击了取消"
);
}
};
}
|
当点击屏幕的时候能够看到以下
点击post便可将内容分享出去。固然该分享方式具备必定的局限性,因此通常咱们都会使用第三方框架。java