参考链接
https://www.jianshu.com/p/21af85107a34
https://developer.apple.com/documentation/app_clips?language=objc
3.App Clips流程使用
3.1启动流程
- 从用户以各种方式与轻 App Clips交互开始,直到用户切换到完整 App。
-
如果存在主App那么App Clips不会被调起、如果不存在、那么唤起App Clips、同时可以引导下载主App。
image.png
3.2 调用场景
- 通过NFC扫描来唤起
- 通过点击Sari提供的基于地理位置的推荐
- 在地图App上点击指定的链接
- 点击网页上的智能推荐横幅
- 通过Messages App分享的链接
- 二维码扫描进入
3.3 App Clips技术限制
App Clip 仅限应用于特定场景,即尽可能快地完成一个任务,即用即走。你可以把它看作主 app 的核心功能应用,对于复杂的任务应该在其对应的主 app 完成,因此某些功能被禁止在 App Clip 中使用。
-
安装包大小 10M 以内
当弹出 App Clip Card 时会立即下载 App Clip,安装包大小的限制保证了用户体验——当用户打开 App Clip 时大概率已经下载好。 -
不能使用指定 Framework
Assets Library, CallKit, CareKit, CloudKit, Contacts, Contacts UI, Core Motion, File Provider, File Provider UI, HealthKit, HomeKit, Media, Player, Messages, Message UI, PhotoKit, ResearchKit, SensorKit, Speech
以上 Framework 不能在 AppClip 使用,若使用了在编译时不会报错,而是在运行时报错或者返回错误的结果。 -
用户隐私相关操作
1.不能跟踪用户信息,也不能通过 identifierForVendor 来获取用户唯一标识。
2.不能持续地获取用户位置,每次使用位置需要请求用户授权,次日凌晨 4:00,会自动关闭授权。再次使用位置时,需要用户重新授权。
3.只允许 App Clip 和其对应的主 app 通信,不允许和其他 app 进行通信,这就导致微信登录分享支付等功能在 App Clip 里使用不了。
4.不能访问苹果音乐、多媒体,通讯录,文件,运动健康,相册等数据。 -
其他复杂任务
1.后台活动:网络请求、位置更新等
2.蓝牙连接
3.App extensions
4.URL schemes
5.内购(In-app purchases)(区别苹果支付 Apple Pay,在 App Clip 是能够使用苹果支付的)
4.开发流程
4.1.证书配置 : bundle iD 、 App Group配置
4.2.创建Extention :App Clips
4.3.配置权限App Clips可访问权限,Info.plist配置
4.4.开发方式
- 通过 App Group 将数据从App Clips 传输到完整 App、
- 通过 SKOverlay 从轻 App 跳转到完整 App
- macros宏:复用主App代码
#ifdef CLIPS
xxxx
#endif
4.5.测试调用 URL 具体步骤如下:
1.点击 Product -> 编辑轻 App 对应的 Scheme
2.添加 Environment variable _XCAppClipURL 这个键值来模拟调用 URL
3.在轻 App 对应 target 运行轻 App 的 scheme。NSUserActivity 获取这个值。
5.调用验证
App Clips 在通用设置->轻App查看(30天自动清除)
5.1 安装方式:
- 使用 Xcode 构建并运行 App Clips
- 使用 Xcode 中 Archive 功能为App Clips 创建 ipa 文件,在设备上安装
- 通过 TestFlight 向用户推送App Clips
5.2 调用方式:
- 轻点 NFC 标签
- iOS 系统相机二维码扫描
5.3 开发测试步骤:
1.真机运行App Clips项目(iOS 14系统),执行对应Extention Target
2.通用设置->开发者>-App Clips Testing->配置URL、Bundle ID 和卡片类型(Open、View、Play)
3.配置URL生成二维码->iPhone 扫码打开-> 唤起App Clips
Share Data Between the App Clip and the App
Your App Clip can make its data accessible to its corresponding app by storing data in a shared container. The full app can then access this data when it replaces the App Clip, providing a positive user experience.
To store data in a shared container:
Add the App Groups capability to targets for both the App Clip and the full app.
For both targets, add the same app group to the capability; for example,
group..example App .app Clip Migration In your App Clip’s code, obtain the URL for the shared container using
containerand store data using the URL; for example, by usingURLFor Security Application Group Identifier: write.To URL: atomically: encoding: error: In your app’s code, use the same function to obtain the URL of the shared container and access its content; for example, by using
init.With Contents Of URL:
In addition to a shared container, the App Clip can also store information in a shared NSUser instance that’s accessible to the full app. The following code uses the configured app group to create the shared User instance and store a string:
guard let sharedUserDefaults = UserDefaults(suiteName: "group.exampleApp.appClipMigration") else { // Error handling}sharedUserDefaults.set("A sample string", forKey: "sharedText")When users install the full app, it can access the shared user defaults. For example, to access the string stored in the previous code:
guard let sharedUserDefaults = UserDefaults(suiteName: "group.exampleApp.appClipDataMigration") else { // Error handling}guard let migratedData = sharedUserDefaults.string(forKey: "sharedText") else { return }To preserve user privacy across apps and App Clips, an App Clip can only share its data with its corresponding app. In addition, you can’t make information the App Clip stores in the keychain accessible to its corresponding full app.

评论
发表评论