iOS 系统原生分享图片 文字 音乐 纯视频 网页
为了方便使用,我封装了一个分享的工具类LFSystemShareUtil。工程要引Social.framework。
LFSystemShareUtil.h
#import <Foundation/Foundation.h>
#import <Social/Social.h> typedef NS_ENUM(NSInteger, LFSystemShareType) {
LFSystemShareWeChat,//微信
LFSystemShareQQ,//腾讯QQ
LFSystemShareSina,//新浪微博
}; typedef NS_ENUM(NSInteger, LFSystemShareState) {
LFSystemShareStateCancel,//取消
LFSystemShareStateDone,//完成
LFSystemShareStateNone,//未安装
}; @interface LFSystemShareUtil : NSObject /**
直接分享到某平台 @param type 平台
@param controller 弹出分享界面的控制器
@param items 可以仅分享图@[UIImage],可以放多张;或者仅分享纯视频、音乐@[NSURL];或者一个带文字和缩略图的网页@[NSURL,NSString,UIImage],等等,总之把要分享的东西放到数组即可
@param shareResult LFSystemShareState
*/
+ (void)shareWithType:(LFSystemShareType)type controller:(UIViewController *)controller andItems:(NSArray *)items completionHandler:(void(^)(LFSystemShareState state))shareResult; /**
通过选择平台的控制面板分享 @param controller 弹出分享界面的控制器
@param items 可以仅分享图@[UIImage],可以放多张;或者仅分享纯视频、音乐@[NSURL];或者一个带文字和缩略图的网页@[NSURL,NSString,UIImage],等等,总之把要分享的东西放到数组即可
@param shareResult 结果回调
*/
+ (void)shareWithController:(UIViewController *)controller andItems:(NSArray *)items completionHandler:(void(^)(NSString *activityType,BOOL completed,NSArray *returnedItems,NSError *activityError))shareResult; @end
LFSystemShareUtil.m
#import "LFSystemShareUtil.h" @implementation LFSystemShareUtil + (void)shareWithType:(LFSystemShareType)type controller:(UIViewController *)controller andItems:(NSArray *)items completionHandler:(void(^)(LFSystemShareState state))shareResult {
NSString *serviceType = @"";
switch (type){
case LFSystemShareWeChat:
serviceType = @"com.tencent.xin.sharetimeline";
break;
case LFSystemShareQQ:
serviceType = @"com.tencent.mqq.ShareExtension";
break;
case LFSystemShareSina:
serviceType = @"com.apple.share.SinaWeibo.post";
break;
default:
break;
} /*
<NSExtension: 0x1741735c0> {id = com.apple.share.Flickr.post}",
"<NSExtension: 0x174173740> {id = com.taobao.taobao4iphone.ShareExtension}",
"<NSExtension: 0x174173a40> {id = com.apple.reminders.RemindersEditorExtension}",
"<NSExtension: 0x174173bc0> {id = com.apple.share.Vimeo.post}",
"<NSExtension: 0x174173ec0> {id = com.apple.share.Twitter.post}",
"<NSExtension: 0x174174040> {id = com.apple.mobileslideshow.StreamShareService}",
"<NSExtension: 0x1741741c0> {id = com.apple.Health.HealthShareExtension}",
"<NSExtension: 0x1741744c0> {id = com.apple.mobilenotes.SharingExtension}",
"<NSExtension: 0x174174640> {id = com.alipay.iphoneclient.ExtensionSchemeShare}",
"<NSExtension: 0x174174880> {id = com.apple.share.Facebook.post}",
"<NSExtension: 0x174174a00> {id = com.apple.share.TencentWeibo.post}
*/ /*
"<NSExtension: 0x174174340> {id = com.tencent.xin.sharetimeline}", //微信
"<NSExtension: 0x174173d40> {id = com.tencent.mqq.ShareExtension}", //QQ
"<NSExtension: 0x1741738c0> {id = com.apple.share.SinaWeibo.post}", //微博
*/ if ([SLComposeViewController isAvailableForServiceType:serviceType]) {
SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:serviceType];
for ( id obj in items){
if ([obj isKindOfClass:[UIImage class]]){
[composeVC addImage:(UIImage *)obj];
}else if ([obj isKindOfClass:[NSURL class]]){
[composeVC addURL:(NSURL *)obj];
} else if ([obj isKindOfClass:[NSString class]]) {
[composeVC setInitialText:(NSString *)obj];
}
} // 弹出分享控制器
composeVC.completionHandler = ^(SLComposeViewControllerResult result) {
if (shareResult) {
shareResult((LFSystemShareState)result);
}
};
[controller presentViewController:composeVC animated:YES completion:nil];
} else {
if (shareResult) {
shareResult(LFSystemShareStateNone);
}
}
} + (void)shareWithController:(UIViewController *)controller andItems:(NSArray *)items completionHandler:(void(^)(NSString *activityType,BOOL completed,NSArray *returnedItems,NSError *activityError))shareResult {
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
//不出现在活动项目
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList];
activityVC.completionWithItemsHandler = shareResult;
[controller presentViewController:activityVC animated:YES completion:nil];
} @end
iOS 系统原生分享图片 文字 音乐 纯视频 网页的更多相关文章
- php表单提交 图片、音乐、视频、文字,四种类型共同提交到数据库
这个问题一直困扰了我好几天,终于在今天让我给解决了,难以掩饰的激动. 其实在之前没有接触到这种问题,只是表单提交数据而已,再就是图片,四种类型同时提交还真是没遇到过,做了一个系统,其中有一个功能就是提 ...
- UIActivityViewController实现系统原生分享
代码地址如下:http://www.demodashi.com/demo/11042.html 一.效果预览 二.接下来介绍UIActivityViewController,跟我动手做 1.创建要分享 ...
- HTML5:图片、音乐和视频
图片.音乐和视频 一.图片 1.属性 属性 说明 alt 规定图像的替代文本. src 规定显示图像的 URL align 规定如何根据周围的文本来排列图像. border 定义图像周围的边框. he ...
- 微信朋友圈如何同时分享(图片+文字) Android版
以下是:微信朋友圈SDK 分享图片的代码,但只能分享图片,不能分享文字,如何才能图片和文字同时分享?求各位大神指教! public class MainActivity extends Activit ...
- iOS系统原生 二维码的生成、扫描和读取(高清、彩色)
由于近期工作中遇到了个需求:需要将一些固定的字段 在多个移动端进行相互传输,所以就想到了 二维码 这个神奇的东东! 现在的大街上.连个摊煎饼的大妈 都有自己的二维码来让大家进行扫码支付.可见现在的二维 ...
- iOS开发-- 利用AVPlayer播放远程音乐和视频
一.简单的播放音乐和视频,播放视频的工具栏需要自己写 二.利用老师封装的框架实现视频播放 链接:http://pan.baidu.com/s/1hrEKlus 密码:8e7g
- 仿简书分享:UIActivityViewController系统原生分享
接下来介绍UIActivityViewController: 1. 创建要分享的数据内容,加在一个数组 ActivityItems里. NSString *textToShare = @"我 ...
- iOS系统原生二维码条形码扫描
本文讲述如何用系统自带的东东实现二维码扫描的功能:点击当前页面的某个按钮,创建扫描VIEW.细心的小伙伴可以发现 title被改变了,返回按钮被隐藏了.这个代码自己写就行了,与本文关系不大...绿色的 ...
- Android APP 分享图片文字到微信刚開始正常,后面就不弹出分享框了
依照官方的流程走了一遍.一切顺利,分享成功了.本来以为能够大功告成了,结果睡了一觉,第二天要给客户演示了.才发现TMD坑爹了,不能分享了,第三方的分享栏弹不出来了.我一阵惊慌,还好非常快找到了解决的方 ...
随机推荐
- Xmind 8 update5 破解
Step 1. Download XMind Step 2. Run XMind at least once after installation, xmind will init the confi ...
- selenium===requestium模块介绍
有时,你可能会在网上实现一些自动化操作.比如抓取网站,进行应用测试,或在网上填表,但又不想使用API,这时自动化就变得很必要.Python提供了非常优秀的Requests库可以辅助进行这些操作.可惜, ...
- python实战===2017年30个惊艳的Python开源项目 (转)
本文转自:http://www.sohu.com/a/216723120_115128 摘要:本文来自Mybridge,介绍了过去一年里30个惊艳的Python开源项目.点击每一个都可以在GitHub ...
- free函数在操作系统内存中的实现【转】
转自:http://www.2cto.com/kf/201210/160985.html 我一次性malloc十个单位节点的内存空间出来赋值给L, 现在我想一次性删除从第3个到第6个节点,我是这么做的 ...
- 12-4 NSString
原文:http://rypress.com/tutorials/objective-c/data-types/nsstring NSString 在本教程的内容可能我们已经看到过很多次了,NSStri ...
- Linux操作系统中内存buffer和cache的区别--从free命令说起(转)
原文链接:http://os.51cto.com/art/200709/56603.htm 我们一开始,先从Free命令说起. Free free 命令相对于top 提供了更简洁的查看系统内存使用情况 ...
- Assistor PS 切图工具的使用说明。
一.如何运行Assistor PS 使用这个Assistor PS 软件有一个最最重要的条件,那就是:你要打开你的Photoshop (官方建议版本在CS 3以上) 下载-安装-运行. 运行成 ...
- Leetcode 之Anagrams(35)
回文构词法,将字母顺序打乱.可将字母重新排序,若它们相等,则属于同一组anagrams. 可通过hashmap来做,将排序后的字母作为key.注意后面取hashmap值时的做法. vector< ...
- django的事务
在某些时候,你可能会在视图修改两张数据表.并且想让他们同时成功或者同时失败.这就是事务的原子性(atomicity).在django中应该怎么做呢? 详细可以参考官方文档:https://yiyibo ...
- 手机端调试console.log,直接引入一个js文件
http://files.cnblogs.com/files/lwwen/mConsole.js 这是我写的一个原生js文件 直接引入即可,可以把html上面的需要打印的东西打印出来 <!DOC ...