这两天一在看iOS的App Extension功能,想把它加到我们的产品中去。
网上搜Demo挺简单,但做到细节的时候单靠Demo是不行的,还需要仔细看看Apple的各种文档。
其中主要是研究了Share Extension 和 Action Extension。
过程中遇到了不少的坑,如下:
一、Share Extension对javascript方法finalize的支持一直没有试出来,Action Extension是支持的,官方也没说哪些支持哪些不支持。
二、plist配置失败(如某个关键值拼写错误)会导至编译通过,但在Host App中显示出来。
三、关于Share Extension自定义UI的问题,去掉默认的弹出发送框,只需要新建storyboard并在plist中声明,ViewController不要继承SLComposeServiceViewController,Extension相关的方法如 NSExtensionContext 默认都是UIViewcontroller的方法,还要注意把Storyboard自定Entry Point,否则会崩溃。而不是像官网上说的,如下:
NOTE
To provide a custom compose view instead of the standard one, deselect “Use standard social compose interface” in the Xcode target-adding pane. When this checkbox is deselected, the defaultSharingViewController
class is based on NSViewController
or UIViewController
, depending on the platform you chose.
参考文档如下:
https://github.com/atomicbird/iOS-Extension-Demo
http://www.cocoachina.com/ios/20141023/10027.html
http://blog.youkuaiyun.com/phunxm/article/details/42715145