Can a restore replace a file in an App Group container while the app's process is alive?

For an iOS app that stores a SQLite database in its App Group container and has no extension targets, can iCloud restore, Finder or Apple Devices restore, or Quick Start replace a file in that container while the app's normal process remains alive, including while suspended? If iOS terminates the process first, can the app relaunch before all App Group files have finished restoring? Please identify any differences between these restore paths and any documented guarantee.

Related: thread 845479 gave the general rule for the app's own container.

Answered by DTS Engineer in 917340022

The answer here is basically the same as that other thread you referenced. The tasks you’re referring too — restoring from backups and Quick Start — are all executed with no app’s running, and so this case will never crop up.

I don’t think this actually documented anywhere though. Lemme ping Kevin to see if he’s aware of something that I missed.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The answer here is basically the same as that other thread you referenced. The tasks you’re referring too — restoring from backups and Quick Start — are all executed with no app’s running, and so this case will never crop up.

I don’t think this actually documented anywhere though. Lemme ping Kevin to see if he’s aware of something that I missed.

Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

For an iOS app that stores a SQLite database in its App Group container and has no extension targets, can iCloud restore, Finder or Apple Devices restore, or Quick Start replace a file in that container while the app's normal process remains alive, including while suspended?

No, though the question itself is somewhat misleading. The system doesn't actually need to worry about terminating apps prior to restoration because it never allows an app to launch before the app is restored. In most cases (there's some degree of parallelism), it doesn't actually download the app itself until it's already restored all of the app's files.

A few notes:

  • The app icon you see on your screen before the app is restored ISN'T actually a "valid" app object to the system itself. It's a special placeholder object, so it can't actually "launch". However, touching it will pump an app's priority in the restore queue so, particularly for small apps, it can look like it "launched immediately" when it was touched when what actually happened is that the restore jumped to the head of the line and completed quickly.

  • One thing that can trip apps up is that we won't (necessarily) have downloaded files from iCloud. Since they're stored in iCloud (not just the device), they aren't included in the backup itself, so they aren't restored. Apps shouldn't have a problem with this, but I have seen cases where apps had problems because they were inadvertently relying on particular iCloud files being present simply because app usage patterns meant they normally WERE present.

  • More generally, many data protection bugs can make it LOOK like your app's files didn't restore when the actual issue is simply that your app is confused about its own state. This forum post describes the issue in detail and this post has my recommendation on what to do if your app is running into these issues.

If iOS terminates the process first, can the app relaunch before all App Group files have finished restoring?

No. App Groups are considered "part" of an app's data, so an app can't be launched until all of its App Groups are present.

I don’t think this actually documented anywhere though.

Yeah, I don't think we ever have, mostly because the actual behavior is so direct—your app won't run until all of its data is there, so there isn't actually that much to document.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware