UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

4      

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

4      

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.

4      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.