My goal is to create an iOS share extension (via Xamarin) that enables an user to upload an audio or video file through my app to my backend via the iOS share menu. The workflow would be like:
- user opens audio or video file (e.g. from Files app)
- taps on the share icon
- share menu opens and shows my app icon in the list
- user taps on my app icon
- the app opens with the view for uploading content, so the user can configure some meta data and finally upload the file
I already achieved this by opening a Dynamic Link from the extension right away. The link contains the path to the file, so the main app knows what file to upload. This is the code for retrieving the file path:
private async Task<string> GetFileUrlAsync()
{
var attachment = ExtensionContext
.InputItems
.Where(x => x.Attachments != null)
.SelectMany(x => x.Attachments)
.First();
var nsUrl = (NSUrl) await attachment.LoadItemAsync(UTType.FileURL, null);
return nsUrl.Path;
}
On the simulator the upload works quite well with the following path:
/Users/tobiasbuchholz/Library/Developer/CoreSimulator/Devices/4FE06C03-50D2-4613-892B-5A2EA611D26A/data/Containers/Shared/AppGroup/834E4479-1A30-474B-B3EA-1840D14BE4DC/File Provider Storage/sample.mp3
On a device on the other hand I'm receiving an exception with the following message:
System.UnauthorizedAccessException: Access to the path "/private/var/mobile/Containers/Shared/AppGroup/A4F8EE6A-A229-4869-81AE-36FE96F9B5FA/File Provider Storage/ABLAZE/sample.mp3" is denied.
So finally, my question: Is there a way to bypass this error on the device? Like an Info.plist setting or something like this that I'm missing. Or do I need to create an app group, copy the file via my extension to this location and access it in the main app from there? (which kinda sucks considering the user's disk space)