views:

2828

answers:

4

If I make two iPhone applications, how can/should I share custom data (not contacts and stuff like that) among them?

Thanks!

+11  A: 

There are two different ways you might go about this.

1) The data you need to share is non-persistent. In other words you need to launch one application with a piece of data that it can do something with. In this case you would register a special URL scheme per application.

You can find out more information about URL schemes via Craig Hockenberry in his [redacted] blog post.

2) The data you need to share is persistent. In other words you need something like a data file that both applications can read and write too. As far as I know there isn't a safe way to do this other than storing your data on a remote server. If you need the data accessible without a data connection then you would need to figure out a way to sync data between the individual apps and the remote server.

Michael Ledford
+11  A: 

In addition to what's already been mentioned, the iPhone documentation on code signing seems to imply that applications signed with the same identity can access the same Keychain items. If you need to store relatively small amounts of data (passwords, etc), this may be a useful technique.

Mark Bessey
Yes after Micheal Ledford's answer, which is correct as far as I know, I began looking into the Keychain, I'm not sure how to get the signing right yet, but it might be a solution to share small data (precisely passwords) among applications.
Robert Gould
+1  A: 

Dan Grisby's most recent mobile orchard podcast hypothesizes that you might also use custom named clipboards to share information between apps. I realize this is an older post, but I thought I would point this out because it's high on google results. :)

(Documentation also suggests that NSUserDefaults might be useful here, but I've read elsewhere that that's actually not the case.)

livingtech
+1  A: 

A hack I can think of is writing to and reading from the Address Book, with the API, storing data in the available fields (+ NSData conversion for the user image perhaps). Edit: I've successfully implemented the NSData conversion and storing of objects inside a contact's display image, thus making them non-editable from the contacts application.

luvieere
+1 for a nice trick, but I expect the end user might be annoyed about having garbage in their address book.
sbwoodside
@sbwoodside Not to worry, we'll pack an Ativan pill with the application, so he'll be less annoyed. On a serious note, I chose the path that offers the full functionality asked about in the question... this comes, as always, with the reminder "be careful what you wish for, you might just get it", in this case, with the mild annoyance of a seemingly blank address book record.
luvieere