Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving files from an iOS app extension to the containing app

I'm working on adding the ability to use the share button to allow users to save files for use with my main application. Multiple file types (image, video, audio, pdf, etc) need to be supported.

A general use case would be: The user takes a picture with the standard Camera app or audio recording using the Voice Memos app. User clicks the Share button and selects my extension from the share list. Dialog opens up giving the user to opportunity to give a description for the file. File is saved to where my main app (the containing app) can later access and process it.

I've been able to get to the point where I am prompted to share the file, but I have not been able to find a location to successfully save to that my main app can later read from. Is this even possible? Is there a better way to handle this scenario?

I am currently doing this using Xamarin so debugging is not supported (and logging is minimal). If someone has an answer in Objective C, that would at least help point me in the right direction.

like image 452
cain Avatar asked Sep 29 '22 10:09

cain


2 Answers

There are a few things that you need to do.

First, your app and your app extension should belong to the same app group:

https://developer.apple.com/library/prerelease/ios/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19

Then you can access the shared storage with something like this:

var groupUrl = NSFileManager.DefaultManager.GetContainerUrl ("stackoverflow.com.mygroup")

Now you can access files in the directory pointed by groupUrl.

like image 55
miguel.de.icaza Avatar answered Oct 07 '22 21:10

miguel.de.icaza


Xamarin's guide to creating Share extensions for iOS: http://developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/

like image 22
NovaJoe Avatar answered Oct 07 '22 19:10

NovaJoe