UIDocumentInteractionController presentPreview crash with second time initialised from webView (WKWebView or UIWebView)

Originator:fassko
Number:rdar://40401511 Date Originated:May 20 2018
Status:CLOSED Resolved:
Product:iOS SDK Product Version:11.3.1
Classification: Reproducible:Always
 
UIDocumentInteractionController  presentPreview crash with second time initialised from webView (WKWebView or UIWebView)


Download source code from: https://github.com/fassko/iOSWebViewDocumentPreviewCrash

1. Need to add WebView (WKWebView or UIWebView) with link to catch custom link
2. Catch custom link from WKNavigationDelegate via decidePolicyFor or UIWebViewDelegate via shouldStartLoadWith
3. Download file
4. Initialise UIDocumentInteractionController with downloaded file
5. Show in current view
6. Download file again and app will crash

Comments

Apple replied:

Engineering has provided the following information regarding this issue:

Your app is trying to use UIDocumentInteractionController from a background thread, directly from a NSURLSession callback, which is not allowed. You need to dispatch_async to the main queue from the NSURLSession callback before doing anything UI-related, including creating and presenting UIDocumentInteractionController.


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!