Docs on updateUserActivityState
are a bit vague to me.
https://developer.apple.com/documentation/uikit/uiresponder/1621095-updateuseractivitystate
Subclasses override this method to update the state of the given user activity. You should add state representing the user's activity into the NSUserActivity object using its addUserInfoEntries(from:) method.
When the state is dirty, you should set the needsSave property of the NSUserActivity to true, and this method will be called at an appropriate time.
So this method is called when we do:
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.userActivity?.needsSave = true
}
And we can then update the activity accordingly:
override func updateUserActivityState(activity: NSUserActivity) {
activity.addUserInfoEntriesFromDictionary(someInfo)
super.updateUserActivityState(activity)
}
But when we only set the activity once and never update it, should we also always have to implement updateUserActivityState
?
For example when setting the activity once in viewDidLoad
:
override open func viewDidLoad() {
super.viewDidLoad()
let activity = NSUserActivity(activityType: "com.myApp")
activity.title = "Viewing"
activity.userInfo = ["myApp.item.key": ["Some", "Things"]]
self.userActivity = activity
self.userActivity?.becomeCurrent()
}