NSItemProvider can’t load relative URLs on iOS

Originator:douglashill
Number:rdar://46030386 Date Originated:14-Nov-2018 01:01 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:Xcode 10.1
Classification:Other Bug Reproducible:Always
 
Summary:
On iOS, when an NSItemProvider is created with an NSURL with a base URL and relative string, the URL can’t be read back from the item provider.

Steps to Reproduce:
Open the attached sample project and run the tests (cmd-U) on iOS.

Long way:

1. Create an NSURL with URLWithString:relativeToURL:
2. Create an NSItemProvider from the URL
3. Try to load the URL from the item provider, either by type (kUTTypeURL) or class (NSURL).

Expected Results:
All 4 tests should pass.

Should load an identical NSURL, preserving the relative part.

Actual Results:
On iOS, only the test with absolute URLs pass: the tests with relative URLs fail.

Coercion fails and an error is returning to the load handler block instead of an NSURL. The case of loading by class is also raising invalid argument exceptions. I haven’t checked if they’re being caught.

Version:
Xcode 10.1

Notes:
This problem does not occur on macOS. It correctly loads the URL there. The tests confirm this.

In practice, the relative URL is being passed to a UIActivityViewController and loaded by share and action extensions. All the third-party apps I tried failed to load the URL (e.g. Slack, OmniFocus, Bear). Interestingly the system apps/actions (e.g. Mail, Messages) seem to handle it fine.

It is possible to not do coercion when loading by type and get back an NSData. Then you have to reverse engineer the format of the data and read that. It’s a binary property list of an array of the relative string then base URL string then an empty dictionary. I’m guessing you wouldn’t recommend we read this.

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!