ClassKit - how to confirm device can save contexts?

I'm updating an app that already has ClassKit compatibility. The app makes a call at launch to get JSON from a server, then creates contexts from that JSON. That works fine. The downside is the app makes a the network call even if the iPad isn't on Apple School Manager - thus would never be able to save the contexts.

We'd like to prevent making the network call unless we know the device has the capability to save contexts. What's the best way to do that?

Replies

There is no API that allows your app to programmatically check if a device is running Apple School Manager (ASM), or check if a user is using a Managed Apple ID.

Keeping your current implementation, (if your device is not running ASM) when your app hits the context save error, one option is to save your JSON to a sandboxed file folder. This will ensure you can fetch the JSON at a later time, and your data will persist through an update to ASM. If the data is stored in a temp folder or the cache, it is susceptible to being purged by the system (especially when updating a device to run ASM). Finally, your app can fetch the JSON at a later time, to avoid making the another network call.

For more information about purgeable and nonpurgeable data: https://developer.apple.com/documentation/foundation/optimizing_your_app_s_data_for_icloud_backup/

For more information about App Sandboxing, see this page from our documentation archive (specifically the section, "Container Directories and File System Access"): https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW15

If your app's contexts are public for all users, you may want to consider pre-publishing them to the ClassKit Catalog, which is a server-to-server endpoint. See this link for more info: https://developer.apple.com/documentation/classkitcatalogapi