LAST CHANCE: Save 50% on all my Swift books and bundles! >>

How to handle first time launch experience when iCloud is required?

Forums > SwiftUI

I am using CloudKit to store publicly available data and the new NSPersistentCloudKitContainer as part of my Core Data stack to store/sync private data.

When a user opens my app, they are in 1 of 4 states:

  1. They are a new user with access to iCloud
  2. They are a returning user with access to iCloud
  3. They are a new user but do not have access to iCloud for some reason
  4. They are a returning user but do not have access to iCloud for some reason

States 1 and 2 represent my happy paths. If they are a new user, I'd like to seed the user's private store with some data before showing the initial view. If they are a returning user, I'd like to fetch data from Core Data to pass to the initial view.

Determining new/old user: My plan is to use NSUbiquitousKeyValueStore. My concern with this is handling the case where they: download the app -> are recorded as having launched the app before -> delete and reinstall/install the app on a new device I assume NSUbiquitousKeyValueStore will take some time to receive updates so I need to wait until it has finished synchronizing before moving onto the initial view. Then there's the question of what happens if they don't have access to iCloud? How can NSUbiquitousKeyValueStore tell me if they are a returning user if it can't receive the updates?

Determining iCloud access: Based on the research I've done, I can check if FileManager.default.ubiquityIdentityToken is nil to see if iCloud is available, but this will not tell me why. I would have to use CKContainer.default().accountStatus to learn why iCloud is not available. The issue is that is an asynchronous call and my app would have moved on before learning what their account status is.

I'm really scratching my head on this one. What is the best way to gracefully make sure all of these states are handled?


Scratching my head on this one as well. How did you go?


This is also a big problem for me so I'm really hoping that someone can provide some guidance. There are lots of apps out there that share private data via iCloud, so there must be some established methods for setting it up.


Click here to save 50% on all my books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.