Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 - Share Documents Directory Between Apps

My team is developing a suite of in-house apps for a large organization, and each of these apps needs access to the same data. This includes large amounts of user data and ~50MB of other data that will come pre-loaded with the app (SQLite), as well as a large number of images and audio files that may be downloaded at any time. Is there any way in iOS 8 to allow these apps to have access to the same files? Something like a shared documents directory would be ideal.

Initially these apps will be released internally under an Enterprise license, but the client would eventually like them to be released on the App Store.

like image 530
Hundley Avatar asked Feb 10 '23 20:02

Hundley


2 Answers

No, you cannot have a shared documents directory, but you can have a shared folder in which you can use as your documents directory. When you create an app group Create an identifier for each of your apps in the app group.

Then you can use the file manager to get the URL for the directory you want with the given group identifier.

let url = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.MTC.DataSender")!

This will return the URL to the directory for the DataSender app. Every app in the app group can access this directory. So in your other app you would do the same thing.

like image 78
Micah Wilson Avatar answered Feb 23 '23 11:02

Micah Wilson


No, you cannot have shared documents directory between apps on iOS. Let alone the fact that Apple doesn't support this, multi-threading on core-data within one app is already buggy enough, I don't think it is a good idea to share your sqlite library with multiple apps. And also, sharing documents between apps (like what Android and Window Phone do) has potential security problems. I think that may also be a reason why Apple doesn't give developers to have direct access to files of other app.

However, with that say, it is still possible to share data or documents between apps. You can take a look at these two: UIActivityViewController and UIDocumentInteractionController. They may not be exactly what you want to achieve, but that's pretty much the best you can do with inter-app communication on iOS so far.

like image 21
Yuchen Avatar answered Feb 23 '23 12:02

Yuchen