iOS简单分享1——自定义分享

关键词:自定义分享列表、自定义事件、URL Schemes、UIPasteboard

提前注意:

以免浪费时间,不涉及Share ExtensionUIActivityViewControllerUIActivity

整体思路

App1:通过URL Schemes+UIPasteboard,分享到App2
App2:AppDelegate中先跳转到分享VC,然后UIPasteboard获取到分享的数据展示。

效果

001.gif

配置

配置URL Schemes,一个工程可以对应多个,分别用逗号隔开就好。

share01.png

适配iOS10

这里主要是指UIPasteboard变动。最新API已经废除persistent属性,新增UIPasteboardOption

UIPasteboardOption有两个值:
UIPasteboardOptionExpirationDate:表示到什么时间移除。
UIPasteboardOptionLocalOnly:表示是否一直在本地,相当于之前的persistent属性

最新存储的用法如下:

 UIPasteboard *pasteboard = [UIPasteboard   pasteboardWithName:@"my" create:YES];            
 if (pasteboard.items.count > 0)
  {
      pasteboard.items = [NSArray array];
  }
           
  NSArray *items = [ShareManager getDataArrFromModel:model Pasteboard:pasteboard];
  [pasteboard setItems:items options:@{UIPasteboardOptionLocalOnly:@YES}];

Demo

需要FirstDemo和SecondDemo一起运行,FirstDemo跳转到SecondDemo。欢迎指正!
demo

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容