I'm trying to implement scene-based state restoration in an iPad OS 13 / macCatalyst app.
The docs say .stateRestorationActivity might be nil in scene(_:, willConnectTo:, options:) if data protection is turned on.
I don't have data protection turned on in my macCatalyst app, but .stateRestorationActivity is always nil, despite my verifying that stateRestorationActivity(for scene: UIScene) -> NSUserActivity? is returning a non-nil activity with an identifier that's set up in my Info.plist and has the target content identifier:
class DocumentViewContoller : UIViewController {
...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
updateDocumentUrlInTitleBar()
let activity = NSUserActivity.newShowActivity() //extension creates this with correct activityType string
activity.targetContentIdentifier = document?.fileURL.absoluteString
activity.title = document?.fileURL.lastPathComponent
view.window?.windowScene?.userActivity = activity
guard isViewLoaded
,let activationConditions = view.window?.windowScene?.activationConditions
else { return }
guard let url = document?.fileURL else {
activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(value: true)
activationConditions.prefersToActivateForTargetContentIdentifierPredicate = NSPredicate(value: false)
return }
activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(format: "self == '\(url.absoluteString)'")
activationConditions.prefersToActivateForTargetContentIdentifierPredicate = NSPredicate(format: "self == '\(url.absoluteString)'")
// activity.becomeCurrent()
}
and I verified that the predicates were set on the scene in stateRestorationActivity(for scene:)
What other conditions do I have to meet in order that my scenes are restored when the app launches again?
If it will always be nil, why did the WWDC presenters, in 3 separate talks, tell us we should look for it in that method?
If it will always be nil in this method, during which delegate callback method should I expect it to be non-nil?
It it will always be nil in all delegate callbacks, then how do I get an app to re-open document scenes which were open when the app was last quit?