Technical Note TN2428

Data Management and Synchronization for Shared iPad

While any app can implement appropriate support for Shared iPad, developers building for the education market will want to adopt the following best practices to ensure that user-specific data is cloud-based and efficiently managed.

Since local data may be purged when switching users or when the device is reconfigured to meet changed classroom use needs, the following best practices describe the recommended approach for ensuring persistent storage depending on your application architecture and the type and volume of user-specific data.

Supporting purgeable local storage means that you either have no persistent content of consequence (for example a calculator app) or your app ensures that any content that requires persistence is stored in the cloud. Once you've implemented the following best practices, you'll want to indicate your support for Shared iPad by setting the NSSupportsPurgeableLocalStorage key to Yes in your project’s Info.plist. Doing so indicates that your app supports having its local data purged when the user logs out.

Data Management Best Practices
Sync Technologies
Document Revision History

Data Management Best Practices

Store all user data in the cloud

Shared iPad requires a cloud-based synchronization model for any data required to persist between uses of the app. Send data to your own backend using NSURLSession, or use iCloud, NSUbiquitousKeyValueStore, and store credentials in Keychain.

Fetch remote data on demand

Since all data associated with a given app may not be required at any given time, develop a download strategy that ensures you only download what’s needed when it’s needed or just before. Rather than bringing back all known user content you may need in the app, consider only pulling what’s required in the current context.

Sync data as it changes

Sync user entered or created data as you get it. Be sure to synchronize during applicationWillResignActive at the minimum but keep in mind that waiting too long or holding an overly large batch for synchronization will provide an inferior user experience and may in rare cases lead to data loss.

Store first launch or progress flags in the cloud

If your app determines the need for a first launch experience based on a flag currently stored in the local file system or NSUserDefaults, you should move these per-user flags to NSUbiquitousKeyValueStore and check there before presenting your first launch experience.

For more information on the NSUbiquitousKeyValueStore, check out the NSUbiquitousKeyValueStore Class Reference and PrefsInCloud sample project.

Limit background task assertion requirements

Limit the amount of work you do in background task assertions to the minimum needed to ensure data consistency and synchronization — generally calls to NSURLSession or iCloud APIs to upload the user's data. These APIs provide support to continue the network operation without blocking the transition between users.

Indicate purgeable local storage support in your project PList

Indicate support for Shared iPad by setting the NSSupportsPurgeableLocalStorage key to Yes in your project’s Info.plist. Doing so indicates that your app supports having its local data purged when the user logs out.

Sync Technologies

Sync using NSURLSession

Apps using NSURLSession with the appropriate background configuration to push user-specific settings or data will be assured that their uploads will continue after the user has switched apps and, more importantly, after the current user has signed out on a shared iPad.

For more information on NSURLSession, review the WWDC 2015 video Networking with NSURLSession, the WWDC 2014 video What’s New in Foundation Networking, and the NSURLSession Class Reference.

Synchronize credentials via Keychain

Keychain on Shared iPad provides automatic synchronization across devices using the same Apple ID. Storing credentials and other lightweight information in Keychain via Keychain Services API ensures they will be secure and available wherever the user signs in.

For more information on Keychain implementation, check out the Keychain Services Programming Guide.

Synchronize data via iCloud

Implementing support for iCloud Documents and Key-Value Storage APIs means your user content will be in-sync without having to explicitly manage that synchronization process. While CloudKit is more transactional and under your explicit control, CloudKit operations are designed to ensure data you've committed arrives in iCloud storage even if the app is exited or the user signs out.

Check out the iCloud Design Guide for which storage API is best for your app.



Document Revision History


DateNotes
2016-02-18

New document that provides best practices to ensure that user-specific data is cloud-based and efficiently managed on a Shared iPad.