Cordova / Phonegap应用程序中的HTML5 localStorage可以同步到iCloud吗? [英] Can HTML5 localStorage in Cordova/Phonegap app be synced to iCloud?

查看:169
本文介绍了Cordova / Phonegap应用程序中的HTML5 localStorage可以同步到iCloud吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在iOS上运行的Phonegap / Cordova应用程序。它会将其数据保存到HTML5 localStorage。



我试图找出是否可以将localStorage数据(使用iCloud)同步到其他iOS设备,甚至操作系统从我可以看到,在iOS localStorage实际上实现为一个SQLite数据库,(当使用Phonegap / Cordova时)写入应用程序的Documents目录:



文件/备份/ localstorage.appdata.db



我也知道有三种主要的储存方式iCloud中的数据:




  • 键/值存储

  • UIDocument / NSDocument

  • 核心数据



我知道我无法使用Key / Value iCloud存储方法, 1MB的数据存储,每个应用程序使用该方法的限制为1MB。



这个问题,我相信是谈论UIDocument方法,并询问是否可以使用该方法在iCloud中存储SQLite数据库文件。答案是否定的,因为数据库可能会损坏。



这样真的离开了核心数据方法。



所以我的问题是 - 这个工作吗?我可以使用Core Data将localStorage.db文件同步到iCloud吗?



我从来没有使用过Core Data,也不太了解它。我只是想知道是否可能,或者如果有其他的东西我不明白。



在iOS设备之间有任何其他方法来同步localStorage数据或OS X?

解决方案

答案不幸地似乎是没有,Core Data不能与HTML5 localStorage一起使用



核心数据不能与使用Core Data创建的SQLite数据库一起使用。如果你尝试,你会得到这个错误在XCode:

  SQLite错误代码:1,'没有这样的表:Z_METADATA'

这是Core数据文档的解释:



https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-SW2


虽然Core Data支持SQLite作为其持久存储
类型之一,但数据库格式是私有的。您不能使用本机SQLite API创建SQLite
数据库,并直接使用Core Data
(也不应使用
本机SQLite API操作现有的Core Data SQLite存储)


我仍然想解决这个问题。我想创建一个反映localStorage API的Javascript API。这将是一个phonegap插件,可以调用objective-c代码,并有效地将其更改写入Core Data数据库。



如果它工作,我会回来并更新这个答案。


I have a Phonegap/Cordova app that runs on iOS. It saves it's data into HTML5 localStorage.

I'm trying to work out if it's possible to sync the localStorage data (using iCloud) to other iOS devices, and even OS X.

From what I can see, in iOS localStorage is actually implemented as a SQLite database, which (when using Phonegap/Cordova) is written to the app's Documents directory:

Documents/Backups/localstorage.appdata.db

I also understand that there are three main ways of storing data in iCloud:

  • Key/Value storage
  • UIDocument / NSDocument
  • Core Data

I know I can't use the Key/Value iCloud storage method, because I have more than 1MB of data to store, and the limitation is 1MB per app with that method.

This question, I believe is talking about the UIDocument method, and asks if it is possible to store a SQLite db file in iCloud using that method. The answer is no because the database may become corrupted.

So that really leaves the Core Data method.

So my question is - would this work? Could I sync the localStorage.db file to iCloud using Core Data?

I've never used Core Data and don't know much about it. I'm just wondering if it would be possible, or if there is something else I don't understand.

Are there any other ways to sync localStorage data between iOS devices or OS X ?

解决方案

The answer unfortunatly appears to be no, Core Data cannot be used with HTML5 localStorage

Core Data can not be used with SQLite databases other than ones created with Core Data. If you try to, you get this error in XCode:

SQLite error code:1, 'no such table: Z_METADATA'

This is explained the Core Data docs:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-SW2

Although Core Data supports SQLite as one of its persistent store types, the database format is private. You cannot create a SQLite database using native SQLite API and use it directly with Core Data (nor should you manipulate an existing Core Data SQLite store using native SQLite API)

I still want to solve this issue though. I'm thinking of creating a Javascript API that mirrors the localStorage API. This would be a phonegap plugin that can call objective-c code, and effectively write it's changes to a Core Data database. The Core Data database should then be able to be synced to iCloud.

If it works, I'll come back and update this answer.

这篇关于Cordova / Phonegap应用程序中的HTML5 localStorage可以同步到iCloud吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆