Reputation: 14203
I'm working on an iPhone application that would allow viewing and editing of data that I want to keep in sync with a desktop application. I don't see anything in the SDK that directly addresses data synchronization, nor can I find anything that allows my to "hook" into the iTunes sync process.
I could do something kludgy like hiding the data in a photo or address book entry, but that just seems like a bad idea. I could use WebDAV or HTTP to get/put data to a server, but it makes the application more complicated.
I guess I was expecting this to be a common use-case for iPhone apps (syncing arbitrary application data between a desktop and the iPhone) and that there would be a set of APIs in the SDK that cover this. Maybe there is and I just can't find it.
Upvotes: 12
Views: 13918
Reputation: 5532
Just to update this answer - in the time since the question was asked, Apple have added support for syncing files to iTunes (and letting the user get to them through iTunes' Apps tab).
To do this, you have to set the UIFileSharingEnabled key to YES in your application's Info.plist file. You can then use standard file IO APIs to save files to your app's Documents directory.
There's more information here: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW6
This includes the behaviour you should implement (i.e. making sure you also support reading documents in that are added into your Documents directory - although I've seen lots of apps that don't do this).
Upvotes: 2
Reputation: 1422
The two popular methods are:
Sync with a desktop app directly via WiFi (using Bonjour etc. to discover the iPhone/desktop app endpoints as others have suggested here).
The other option is to sync with a shared file location - either FTP, MobileMe, WebDAV, web services on another server, etc. So the iPhone and desktop app would read/write to the shared location so the other can see the updates.
As others have said, there is no Apple provided method (using iTunes or otherwise) at this point and no indication that anything along those lines will be happening in the near future unless it's bundled with the iPhone's future support for third-party push updates. (I really doubt this will be the case, but you never know.)
Upvotes: 5
Reputation: 84328
It's a common problem, but unfortunately not addressed by the SDK.
Since the iPhone supports Bonjour service publishing and discovery, you can easily publish a service on the phone and listen for it on the desktop, connecting when they find each other. (Or you can publish the service on the desktop and connect from the phone, either way it doesn't matter.) All of the documentation on Bonjour for MacO OS X applies to iPhone OS.
Note that Bonjour just advertises a service; once you find it, you still have to use sockets to connect and transfer data.
Basically, there is no easy way to do it, but there are enough tools available that you can make the sync experience painless for the user.
Upvotes: 3
Reputation: 25705
I'm also working on an application that needs to share data, the only reasonable/non hack way I found to get information in and out of the iPhone is through NSURLConnection.
(personal opinion) I don't foresee Apple providing hooks to the sync process.(/personal opinion)
Upvotes: 1
Reputation: 69835
I haven't tried this out myself, but I think Bonjour provides the ability to connect with services on other machines, you might find some answers looking into that
Upvotes: 4