Search code examples
iosios-app-group

What is the expected lifecycle of iOS 8 App Group directories?


I am starting to investigate iOS 8 extensions, and I see that App Groups are the mechanism provided to pass data between the host app and the extension. This data sharing can be done with NSUserDefaults, flat files, and core data. When you setup an app group, a new directory is created on the device/simulator that is outside the application sandbox. That directory can be accessed from the host app and the extension, and it would appear that other apps from the same account/team can also access this directory.

Given all of this, I would like to know what the lifecycle of the shared App Group directory and its contents are. I have been unable to find any Apple documentation explaining this. Some empirical testing on the simulator has shown that when more than one application is installed that is accessing the app group, the directory is removed when the last application that has that App Group entitlement is removed. This is what I expected to see. I'd like some confirmation that this is the case. Also, is there any potential for the system purging this location under low disc conditions?

I'm trying to determine if it is "safe" to store my app's primary core data database in this App Group location, or if I should be making copies of data there instead. I don't want my main database to get wiped out from underneath me unexpectedly by the system.

Also, what is the intent for App Group directories? Should they be used for sharing data with extensions only, or are they intended as a general data sharing mechanism between apps from the same developer account/team?


Solution

  • I also posted this on the Apple Dev forums, and got an answer back from someone in Apple developer relations. Here is what they said:

    Is there any potential for the system purging this location under low disc conditions?

    That won't happen.

    I'm trying to determine if it is "safe" to store my app's primary core data database in this App Group location, or if I should be making copies of data there instead.

    Placing your core data store in an App Group directory is perfectly reasonable.

    Also, what is the intent for App Group directories?

    They are there so that suites of apps can shared data. I think the clearest expression of this comes from the Mac documentation. The "App Sandbox Design Guide" says:

    [...] an application can use the com.apple.security.application-groups entitlement to request access to a shared container that is common to multiple applications produced by the same development team. This container is intended for content that is not user-facing, such as shared caches or databases.

    Documentation