Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone offline application with synchronization

I'm looking into building an application which works just as well offline as it does online. Since the application cannot communicate with the server while in offline, there is some level of synchronization which needs to take place.

What are some good tools to read about and start thinking about when planning offline operations with synchronization for your iPhone?

What tools would I have to create on my own, versus tools that apple already provides to help with this particular issue?

like image 722
Coocoo4Cocoa Avatar asked Mar 27 '09 02:03

Coocoo4Cocoa


People also ask

How do you Sync songs offline on iPhone?

Download a song, album, or playlist: Touch and hold music you've added to your library, then tap Download. at the top of the screen. Note: You must turn on Sync Library to download music from Apple Music to your library (go to Settings > Music, then turn on Sync Library).

Will iPhone automatically Sync when connected?

Simply select the “Automatically sync when this [device] is connected” checkbox in the General pane, then turn on syncing for each type of content you want to sync. Your Mac and iPhone or iPad update to matching content whenever you connect them.

How do I get my iPhone to automatically Sync data?

Step 1: Tap on the menu in the top left to see your preferences and other options. Step 2: Tap on the Auto Sync text to open auto sync preferences on your device. Step 3: Tap the green Turn Auto Sync On button to enable auto sync. Step 4: You can now see that auto sync is enabled on this screen.


1 Answers

I've been working on an app that handles this exact behavior for the last 2 months or so. It has a small subset of functions which are online only and a large set of functionality that is offline/online.

I'm using sqlite for local storage as suggested here with a modified version of the sqlitepersistentobjects library. The base version of sqlitepersistentobjects is not thread safe so watch out if you are using it. (check out objectiverecord in: objectivesync for a thread safe alternative but be prepared to dig into the code). If you are willing to develop for the 3.0 sdk then core data is another possibility for a sqlite library.

The overall architecture is simple enough I have modeled local storage using sqlite and remote interaction using objective resource against a rails app and REST api. It can use either xml or json for data serialization.

When an object is modified locally the change is first saved to the sqlite database record for that object and then added to a queue which is serialized and stored in the local sqlite db as well. (The queue can then be processed at any time)

If there is a connection available any queued local changes are deserialized and added to an NSOperationQueue which then processes them in the background.

In order to make this all work I've subclassed NSOperation so that it can support several types of remote queue operations - create, update, delete essentially using objective resource to make the remote requests.

The nice thing about using NSOperationQueue and NSOperation is that they handle the background threading for you so I'd highly recommend having a look at the apple docs for those classes and also at the apple threading guide.

When the application loads there is a bit of remote checking done and processed in the background to pull down the latest data - although to be honest I am still changing the way this behaves a bit.

That's a quick overview of what I've had to deal with so far...hope it helps a little.

like image 195
paulthenerd Avatar answered Sep 21 '22 19:09

paulthenerd