I was trying to share functionality between the main app and wanted initially to embed some storyboard from main app.
On changing my plist entry of
UIMainStoryboardFile, from Main to a newly added storyboard in the same target membership, I get a wicked crash. I'm guessing this is a bug?
2ndly, is this possible (re-using storyboard from main app, obviously after adding to target etc)?
Alex.
On changing my plist entry of
UIMainStoryboardFile, from Main to a newly added storyboard in the same target membership, I get a wicked crash. I'm guessing this is a bug?
2ndly, is this possible (re-using storyboard from main app, obviously after adding to target etc)?
Alex.
I think your question is largely about how to bundle multiple distinct UIs into a single app clip? There isn't one answer to how to accomplish this, you're welcome to use any technology in the SDK. However, if you'd like to bundle multiple storyboard files (ex: Store.storyboard, Restaurant.storyboard, MobileOrder.storyboard) for distinct experiences it will probably be easiest to declare none of these in your Info.plist, or to declare a fallback UI there. Instead you can use something like UIStoryboard.instantiateInitialViewController() to create the view controller you desire at runtime, by inspecting your activation context.
As an example, let's say that in your app clip target you have all three of those storyboard files mentioned above. You could remove the main storyboard key from your Info.plist and perform all setup in code (see example below) or you could leave the Info.plist key and just make sure that it points to a storyboard that could be launched in a generic case.
How you determine what controller/storyboard maps to what URL is specific to your use case and something you get to decide, but hopefully this provides some illustration. I also want to call out the additional state of currentURL. If your app clip is handling multiple experiences, its important to not always reset the state of your UI without checking that the experience actually changed. Say someone used an iMessage link to start and order, went away, and then came back to that order by using the iMessage link again. In that scenario we'll deliver a new NSUserActivity to signal the re-activation, but you probably shouldn't throw away the current order.
As an example, let's say that in your app clip target you have all three of those storyboard files mentioned above. You could remove the main storyboard key from your Info.plist and perform all setup in code (see example below) or you could leave the Info.plist key and just make sure that it points to a storyboard that could be launched in a generic case.
Code Block class AppClipSceneDelegate : UIWindowSceneDelegate { var window: UIWindow? var currentURL: URL? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } window = UIWindow(windowScene: windowScene) window?.rootViewController = SomeDefaultViewController() window?.makeKeyAndVisible() if let userActivity = options.userActivity { scene(scene, continue: userActivity) } } func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { guard let url = userActivity.webpageURL, url != currentURL else { return } currentURL = url window.rootViewController = makeViewController() } private func makeViewController() -> UIViewController { let storyboardName: String if currentURL.path.hasPrefix("store/") { storyboardName = "Store" } else if currentURL.path.hasPrefix("restaurant/") { storyboardName = "Restaurant" } else { storyboardName = "MobileOrder" } return UIStoryboard(name: storyboardName).instantiateInitialViewController()! }}
How you determine what controller/storyboard maps to what URL is specific to your use case and something you get to decide, but hopefully this provides some illustration. I also want to call out the additional state of currentURL. If your app clip is handling multiple experiences, its important to not always reset the state of your UI without checking that the experience actually changed. Say someone used an iMessage link to start and order, went away, and then came back to that order by using the iMessage link again. In that scenario we'll deliver a new NSUserActivity to signal the re-activation, but you probably shouldn't throw away the current order.