Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How enable iCloud support for sqlite?

Tags:

sqlite

icloud

I want to provide iCloud support for my wrapper around sqlite. Is not using coredata.

I wonder how enable iCloud for it. The database content is changed all the time (is for invoicing). Also, if is possible to have some kind of versioning will be great.

Exist any sample I can use to do this?

like image 841
mamcx Avatar asked Aug 09 '11 21:08

mamcx


People also ask

Does Apple use SQLite?

Apple uses SQLite in many (most?) of the native applications running on Mac OS-X desktops and servers and on iOS devices such as iPhones and iPods. SQLite is also used in iTunes, even on non-Apple hardware.

Can I use SQLite for an iOS app?

There are a couple of reasons why developers choose to use SQLite. Some consider it to be the best database for their iOS app because of its easy implementation. For instance, as it is lightweight, embedding the software into devices such as mobile phones and digital cameras is a breeze.

How do you access SQLite using iOS mobile application?

Step 1 − Open Xcode -→ Single View Application -→ Let's name is DBSqlite. Step 2 − Let's develop our UI, Open Main. storyboard and add one text field and two buttons as shown below. Step 3 − Create @IBAction for both the buttons and @IBOutlet for text field and name them btnInsert, btnShowData and name respectively.

How SQLite manage data in iOS apps?

Step 1 − Create a simple View based application. Step 2 − Select your project file, then select targets and then add libsqlite3. dylib library in choose frameworks. Step 3 − Create a new file by selecting File→ New → File...


2 Answers

The short answer is no, you would need to use Core Data as you suspected. Apple has stated that sqlite is unsupported.

Edit: Check out the section on iCloud that's now in the iOS Application Programming Guide under Using iCloud in Conjunction with Databases

Using iCloud with a SQLite database is possible only if your app uses Core Data to manage that database. Accessing live database files in iCloud using the SQLite interfaces is not supported and will likely corrupt your database. However, you can create a Core Data store based on SQLite as long as you follow a few extra steps when setting up your Core Data structures. You can also continue to use other types of Core Data stores—that is, stores not based on SQLite—without any special modifications.

like image 194
kris Avatar answered Sep 23 '22 18:09

kris


You can't just put the SQLite database in the iCloud container, because it might get corrupted. (As you modify an SQLite DB, temporary files are created and renamed, so if the sync process starts copying those files, you'll get a corrupt database.)

If you don't want to move to Core Data, you can do what Core Data does: store your database in your document folder, and store a transaction log in the iCould container. Every time you change the database, you add those changes to a log file, so you can play them back and make equivalent changes on other devices.

This gets pretty complicated: aside from getting the log/reply logic right, you'll want to coalesce redundant changes and periodically collapse the log into a complete copy of the database.

You might have an easier time developing a solution if you can exploit knowledge of your application (Core Data has to solve the problem in the general case). For example, you could save invoices as separate files in the cloud container (text, Property List, XML, JSON, whatever), writing them out as the database changes and only importing ones if the system tells you they were created or changed.

In summary, your choice is either to migrate to Core Data or write a sync solution yourself. Which one is best depends on the particulars of your application.

like image 22
benzado Avatar answered Sep 20 '22 18:09

benzado