- share extension是什么?
- 分享一个网页、或者内容(包括图片、视频、文字、url等)给其他人
- 创建一个share extension
- 苹果建议通过模板来创建extension,因为会自动帮你生成很多配置项,包括分享的viewController;
- 操作步骤
![](http://km.oa.com/files/post_photo/785/217785/6a7c0349d346a9ef206942bd5a0571bc.jpg)
![](http://km.oa.com/files/photos/captures/201410/1413527684_87.jpg)
- 理解share extension
- 方便用户发布内容
- 如果可以,让用户内容预览、编辑、注释以及修改内容
- 在用户发送之间对内容进行校验
Key | Description |
---|---|
| Include this key to indicate to the system and to other apps that your app supports a maximum number of attachments. |
| Include this key to indicate to the system and to other apps that your app supports a minimum number of attachments. |
| Include this key to indicate to the system and to other apps that your app supports files in general. |
| Include this key to indicate to the system and to other apps that your app supports image files. |
| Include this key to indicate to the system and to other apps that your app supports movie files. |
| Include this key to indicate to the system and to other apps that your app supports text. |
| Include this key to indicate to the system and to other apps that your app supports web URLs. |
| Include this key to indicate to the system and to other apps that your app supports web pages. |
- 设置分享的数据类型
- value设置项为允许分享的最大数量,例如图片设置为1,则不能分享多图;
- 如果不允许分享改数据类型,可以设置为0,或者取消键值;
![](http://km.oa.com/files/photos/captures/201410/1413527704_91.jpg)
- Debug extension
- debug时需要选中share extension的target进行编译;
- 编译完会弹出手机的程序供你选择,例如相册、safari、其他App
![](http://km.oa.com/files/photos/captures/201410/1413527713_38.jpg)
![](http://km.oa.com/files/photos/captures/201410/1413527724_36.jpg)
- 数据共享
- 将container app和target设置为同个 app groups,允许访问共享数据;
- 使用NSUserDefaults存储数据;
- 执行发表操作
- 调用 didSelectPost函数
- 使用NSURLSession进行上传
- 不能持续执行后台任务
- post操作后不能再给出提示框
- 不能使用scheme呼起container app,需要使用NSExtensionContext来做交互
![](http://km.oa.com/files/photos/captures/201410/1413527819_58.jpg)
- 测试关注点
- info.plist配置是否正确
- 只允许分享一张照片
- 登录态的校验
- 上传前
- post数据校验----
- 字符串长度
- emoji表情
- 自定义分享页面的测试
- 地理位置
- 分类选择
- 数据请求与处理
- 自定义分享页面的跳转
- 进入分类选择
- @好友选择
- 点击post后的测试
- 不能持续时间太长,多长?
- 唤起container app的验证
- 跳转对应页面
- 无登陆时,全新安装时的处理逻辑
![](http://km.oa.com/files/photos/captures/201410/1413527834_100.jpg)
![](http://km.oa.com/files/photos/captures/201410/1413527845_36.jpg)
![](http://km.oa.com/files/photos/captures/201410/1413527859_59.jpg)
![](http://km.oa.com/files/photos/captures/201410/1413527868_80.jpg)