


应用片段让用户可以快速体验应用。一个应用片段是应用的一小部分,可以在需要的时候被发现。应用片段快速而轻巧,因此用户可以快速打开它们。




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
。
第二步:(可以不)写代码
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
,如下图:

