NSUserActivity's 'Current' State not Properly Managed by UIKit

Originator:googleaccount
Number:rdar://44727935 Date Originated:24-Sep-2018 08:58 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:12.0
Classification:Other Bug Reproducible:Always
 
Summary:
Documentation for NSUserActivity states that the developer can use `-becomeCurrent` and `-resignCurrent` to manually manage which activity is broadcast for handoff or donated for Siri Shortcuts. The documentation, however, recommends that this should be left up to UIKit. The documentation states that by assigning the user activity to your view controller, UIKit will manage this automatically as view controllers are presented and dismissed. However, this does not appear to work correctly.

Steps to Reproduce:
0) See attached Xcode 10 Sample Project
1) Create a new project with two NSUserActivity types in the info.plist
2) Assign a user activity to the root view controller
3) Assign a different user activity to the presented view controller
4) Override `-updateUserActivityState:` in both view controllers so that we can monitor whether the system is managing the user activities
5) Present and dismiss the view controller.

Expected Results:
When the root view controller appears on screen, the `-updateUserActivityState:` method on the root view controller should be called and a print statement should go to the console. When the presented view controller is presented, its `-updateUserActivityState:` method should be called and a print statement goes to the console. When dismissing the presented view controller, the  `-updateUserActivityState:` method of the root view controller should be called.

All of this activity should be managed for the developer by UIKit, at least according to the documentation.

Actual Results:
Depending on where the user activity is assigned to the view controllers, there are different results:

In the sample project, the user activity is assigned during INIT. In this case, the root view controller’s activity is read correctly on launch. But the presented view controller’s activity is not read. Also, when the presented vc is dismissed, the root vc user activity is not made current again.

If the user activity is assigned in viewDidLoad, then the root view controller’s activity is not make current on launch but the presented view controller’s activity is. But still, when the presented view controller is dismissed, the root view controller’s activity is not updated again.

In this case, it is the developer’s responsibility to track when an activity becomes current or not, which the documentation said should be managed automatically.

Version:
12.0

Notes:
Documentation for this can be found here: https://developer.apple.com/documentation/sirikit/donating_shortcuts?changes=_4#2985637

“Next, call the becomeCurrent() method on the user activity object to mark it as current, which donates the activity to Siri. Alternatively, you can attach the object to a UIViewController or UIResponder object, which also marks the activity as current.”

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!