how do I use requestSceneSessionActivation to trigger a specific scene?

In the WWDC videos, they keep saying use `requestSceneSessionActivation` to activate a scene, and I have a scene configuration listed in my info.plist I'd like to activate, but I don't understand how to tell the method which scene to activate.


Specifically, for a multi-document app, I'd need to activate scenes from "New" and "Open" menu commands in UIKitForMac. This would involve a UIDocumentBrowserViewController-based scene. In these cases, I can't just supply a file path in the activity, because the file path isn't known yet. Is there a way to specify the NSUserActivity type in the scene configuration in the Info.plist that i missed? Or maybe a way to invlude the scene configuration name in the user activity?


It sure would be nice if they updated the document-based app templates to use scenes, you know, since it's a big deal and all.

Replies

I don't know if there's a "plist" way to do this, but I found a way to do it in code.


In my app delegate

class         : UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession,      options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  if options.userActivities.filter({$0.activityType == "com.myCompany.myApp.myDocument.new"}).first != nil {
  //new document scene configuration
  return UISceneConfiguration(name: <my document scene name>, sessionRole: .windowApplication)
  }
  //default
  return <my default scene configuration>

and then in my new doc method I call


let userActivity = NSUserActivity(activityType: "com.myCompany.myApp.myDocument.new")
  app.requestSceneSessionActivation(nil, userActivity: userActivity, options: nil) { (error) in
}



and then in various scene delegate methods, the user activity is available. However, I haven't been able to make UIDocumentBrowserViewController create a new document programatically, so I can't post the rest of the code, since I'm not really sure which of several scene delegate methods I am suppossed to use.