iCloud Key Value Storage Issue

147 Views Asked by At

I have the following code to push the app's data to the cloud and update the device storage using the iCloud values.

However, it does not update the on device storage with the iCloud values.

The two most important values to sync are coins and points, I have include both in the code below in case there is a problem with that.

Update iCloud:

func updateiCloud(){
    if (Reachability.isConnectedToNetwork()){

        if (defaults.bool(forKey: "UpdatedLocal")){
            iCloudKeyStore?.set(Int64(points), forKey: "Points")
            iCloudKeyStore?.set(Int64(coins), forKey: "Coins")

            iCloudKeyStore?.synchronize()
            //other values are synced
        }
    }
}

Update Local:

func updateLocal() {
    if (Reachability.isConnectedToNetwork()){
        if (!defaults.bool(forKey: "UpdatedLocal")) {
            defaults.set(iCloudKeyStore?.longLong(forKey: "Points"), forKey: "Points")
            points = defaults.integer(forKey: "Points")
            defaults.set(iCloudKeyStore?.longLong(forKey: "Coins"), forKey: "Coins")
            coins = defaults.integer(forKey: "Coins")

            defaults.set(true, forKey: "UpdatedLocal")
        }
        else {
            defaults.set(false, forKey: "firstLaunch")
            AppDelegate.firstLaunch = false
            defaults.set(true, forKey: "UpdatedLocal")
        }
    }
    else {
        defaults.set(false, forKey: "UpdatedLocal")
    }
}
0

There are 0 best solutions below