2

I am using Ionic with the following plugin: cordova-plugin-icloudkv to persist data in Apples iCloud.

I call:

sync(successCallback/*(dictionary_with_all_sync_keys)

then:

save(key, value, successCallback)

Which saves, i.e. I can access it again with:

load(key, successCallback/*(value)*/, failCallback)

and get the saved value as expected.

Problem

When I close the app, and restart it, and try:

sync(successCallback/*(dictionary_with_all_sync_keys)

then:

load(key, successCallback/*(value)*/, failCallback)

I get:

key is missing

It is as if, the value is not being persisted to iCloud, but rather only local storage, which is lost when the app is closed.

Question

How can I make the above persist to iCloud?

Thanks

Richard
  • 8,193
  • 28
  • 107
  • 228

1 Answers1

1

I guess you may have to read the plugin usage once again in the official link

It states as follows,

Reminder: Calling sync does not guarantee (or matter for) syncrhonization with iCloud but only between the in-memory and the flash storage that will be eventually synced with iCloud by an independent agent.

So the syncing actually depends on the independent agent. This plugin just pushes the data that can be made available for syncing. Hope it helps

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • I see that the cordova-plugin-icloudkv wraps `NSUbiquitousKeyValueStore`. Doesn't that mean that it should sync with `iCloud`? Because `NSUbiquitousKeyValueStore` will do all the work, i.e. is the "independent agent"? I see my App doesn't have `iCloud Containers` set up. I will do so, and test. Will report back if it works. https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForKey-ValueDataIniCloud.html – Richard Jul 14 '17 at 07:49
  • @Richard Check this out - https://stackoverflow.com/questions/11389516/nsubiquitouskeyvaluestore-sync-issues The sync frequency is system controlled and my not be rea time. NSUbiquitousKeyValueStore jus notifies the icloud that data is available for sync – Gandhi Jul 14 '17 at 07:55
  • 1
    I just tested my app with `iCloud Containers` set up, i.e. with the my Provisioning Profile having an `iCloud` enabled service. And it works!! I can uninstall my app, and then when I install it again, and `load` the k-v pair, the value is retrieved. – Richard Jul 14 '17 at 08:02
  • 1
    So my issue was that I did not have `iCloud` enabled for my provisioning profile. – Richard Jul 14 '17 at 08:03
  • @Richard Great. But please be informed that the sync dont guarantee a real time sync. Will catch up soon on other issue. Cheers – Gandhi Jul 14 '17 at 08:09
  • Thanks, what do you think I should do to guarantee a sync? When I need the data, which is only when the user logs into the app, I call `sync`, and then `restore`. Testing it a few times worked every time, but if you say it's not always guaranteed, do you know what I can do? – Richard Jul 14 '17 at 08:11
  • @Richard As mentioned in the link i sent earlier, the sync is system controlled. Atleast you have to wait a minute or two to guarantee that the sync happens – Gandhi Jul 14 '17 at 08:14
  • I see. Thank you, I really appreciate the advise you gave me here, helped a lot. – Richard Jul 14 '17 at 08:16
  • 1
    @Richard Thanks to you too Richard as it was a new learning. Cheers – Gandhi Jul 14 '17 at 08:20