9

If I make an app in PhoneGap that uses localStorage to store key/value data, will this data be synched to other devices via iCloud? I don't need to save much data.

kschaos
  • 95
  • 1
  • 7

4 Answers4

21

I disagree with @sciritai.

localStorage in iOS is just an SQLite db file that is stored somewhere on the device.

Perhaps things were different in a previous Phonegap/Cordova version, but in the current version Phonegap writes the localStorage.db file into the Documents directory for your app.

Specifically: Documents/Backups/localstorage.appdata.db

Since the Documents directory is specific for each app, it will be automatically saved to iCloud.

I can confirm this when I check out the iCloud settings in iOS (under Storage & Backup > Manage Storage).

I can see that my HTML5 iOS app is being backed up to iCloud. And that includes the data in the localStorage :)

I believe that means if you have multiple devices, that the localStorage would be synced between them - although I have not confirmed that myself. I'm not sure how iOS would deal with conflicts in the localStorage file actually.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
asgeo1
  • 9,028
  • 6
  • 63
  • 85
7

I'm with @asgeo1 on this on this one. An phonegap app I just submitted has been rejected by apple because it makes heavy usage of local storage of temporary files and these were being entered into backups on icloud.

The fix is to add this to your config.xml:

<preference name="BackupWebStorage" value="none" />
ED-209
  • 4,706
  • 2
  • 21
  • 26
  • 1
    According to the docs at https://cordova.apache.org/docs/en/latest/config_ref/ the default value is `cloud` and the allowed values are `none`, `local`, `cloud` Set to `cloud` to allow web storage data to backup via iCloud. Set to `local` to allow only local backups via iTunes sync. Set to `none` prevent web storage backups. – Jim Bergman Mar 02 '17 at 22:16
5

Just like asgeo1 says, localstorage does get saved to the iCloud. You can turn this off by setting BackupWebStorage to none in the config.xml. Here is a link to the Phonegap documentation.

Note that only user data may be stored to the iCloud. Data that is needed for offline purposes may not be stored in the iCloud. Here is a link to Apple's Q&A.

Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69
Dibran
  • 1,435
  • 16
  • 24
-2

No, localStorage is browser based and persists through the UIWebView that Phonegap gives you to play in, it's not tied to an app.

You can write a plugin to access the documents directory to save information to iCloud with Phonegap.

Old incorrect information here. See @asgeo1's answer below.

sciritai
  • 3,688
  • 1
  • 17
  • 22