其他
「苹果小程序」App Clips 和微信小程序区别在哪?我们做了一次上手实操
应用片段让用户可以快速体验应用。一个应用片段是应用的一小部分,可以在需要的时候被发现。应用片段快速而轻巧,因此用户可以快速打开它们。
信达雅的翻译就是:「无需下载,用完即走」。乍看之下确实像小程序。不过 App Clips 的起源,要从 2016 年 6 月说起。
Xcode 会自动配置以下内容:
在
Signing &
Capabilities
新建On Demand Install Capable
AppClip.entitlements
属性列表文件,默认包含一个key
:com.apple.developer.parent-application-identifiers
,值为包含原始target
的identifier
的数组,demo 的identifier
为com.ifanr.BookShelf
。BooKShelfClip
的默认identifier
以原始target identifier
作为前缀,后面加上.Clip
。在BookShelfClip Target
中identifier
为com.ifanr.BookShelf.Clip
。
第二步:(可以不)写代码
首先,在 BookShelfClip 目录下的 SceneDelete.swift 文件的方法func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
中将 HomeView
作为初始启动界面,代码如下:func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = HomeView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
HomeView
从哪里来的呢?这就是 App Clip 开发上的便利:可以不写代码。通过和原始 Target: BookShelf 共享文件,BookShelfClip 可以直接使用 BookShelf 中已经写好的 HomeView
,如下图:由于目前的 Xcode-beta 版本,在导入一些第三方库时会报编译错误。在这个 Demo 中,我们简单演示了如何使用 SwiftUI (几乎没有写代码)开发简单的 App Clip,可以在 GitHub Repo(https://github.com/ifanrx/hydrogen-demo/tree/master/swiftui-demo/BookShelf-Clip)获取。下一章节,我们将为大家演示:1.集成知晓云后端云服务 SDK 的全功能 App Clip;2.通过 URL、扫码等方式打开 App Clip 的配置、实际效果。下一章,我们还会聊一聊更多的细节,比如 App Clips 只能维持 8 小时的通知机制。恰好微信小程序在灰度发布几大特性,和 App Clips 的特性结合着看,这还有不少值得思考和展望的地方。下期见。由于微信公众号近期改变了推送规则,如果你想如常看到我们的文章,可以在每次阅读后,点击文末右下角的「在看」。这样操作后,我们每次新的推送才能第一时间出现在你的订阅列表中~
▽ 点击「阅读原文」,让你的小程序开发快人一步。