UIKit should detect if extension completes before view appears

Originator:douglashill
Number:rdar://45432578 Date Originated:20-Oct-2018 07:14 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:12.0
Classification:Enhancement Reproducible:Always
 
Summary:
If a share or action or extension calls completeRequestReturningItems:completionHandler: before the view appears, UIKit can attempt to dismiss the extension hosting view controller before presenting it, leaving the host app unresponsive.

This can happen for extensions that don‘t need any input from the user, such as an app that saves text or URLs for access later.

What seems to happen on the second invocation of the share sheet is:

1. Host app presents a UIActivityViewController
2. When the users selects the share extension, the UIActivityViewController  gets dismissed somehow and UIKit starts the extension process if needed and creates the extension UI.
3. In the extension, viewDidLoad is called.
4. The extension completes the request.
5. Back in the host app UIKit, calls dismissViewController on the topmost view controller to dismiss the extension hosting view controller.
6. In the host app, UIKit presents the extension hosting view controller on the topmost view controller.

At step 5, the extension hosting view controller hasn’t been presented yet. The UIActivityViewController is still being dismissed, and there is a warning log about this.

The end result is touch input is blocked in the host app so it needs to be killed by the user.

UIKit should be able to detect this situation and either wait to dismiss after presenting, or log a warning or assert so developers know they abused the API immediately.

Steps to Reproduce:
1. Run the share extension in the trivial attached sample. E.g. in Safari.
2. Invoke the extension twice — the problem does not occur the first time.

The only thing significant in the example is that the share extension calls completeRequestReturningItems:completionHandler: before viewDidAppear: is called.

Expected Results:
Either UIKit complains (such as with an assertion or warning log) both times the extension is run, and/or the host app (e.g. Safari) is usable after the second invocation.

Actual Results:
After the second invocation of the share extension, the host app is unresponsive.

Version:
12.0

Notes:
Regression: I never observed this problem on iOS 11.

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!