'iCloud data backup troubles
I am developing an app with iCloud storage (by default) and local storage compatible. User can choose which one to use. Currently it work well. I can store my core data, and my key value on my cloudKit container.
Now talk about core data and how and save information. With core data I save all the app data, objects and information. On of this entity is "User" with 3 attributes firstName, lastName, photo.
When the didFinishLaunchingWithOptions method is executed, it check if there is a User object saved on cloudKit if true enter normally in the app, if false show a register vc which asks you your information (firstname, name, photo).
So now let's talk about the problem. I can delete the app from my device and reinstall to get back all my data BUT when I open the app the user check is done before data is totally downloaded so it return false and always how the register vc.
What if user reinstall the app and then open it when there's no internet access ? It will always return false because data is not yet backed up ...
If I wait few seconds for the fetch request end and force quit the app to reopen again, data is downloaded so it open normally
So how could I do to have something natural like other apps that you don't have to worry when you reinstall?
I can get iCloud users firstname and name from iCloud account by asking permission but not the photo. I think the best option is to keep a "User" entity for local and iCloud users to keep the same system for both. Also there can't be more than one "User" entity saved.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if CoreDataHelper().getUserObject() != nil {
let otherController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "tabBarController") as? tabBarController
self.window?.rootViewController = otherController
} else {
let pageController = UIStoryboard(name: "quickStart", bundle: nil).instantiateViewController(withIdentifier: "pageVC") as! firstUsePageVC
self.window?.rootViewController = pageController
}
return true
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
