Reputation: 27295
Is anyone aware of any sample or open-source code that does this? Or a write-up explaining how to do it?
Apple has quite a bit of sample code that opens web addresses in other apps. But I can't find any examples where the app asks another app to open a file that is stored on the phone.
Thanks.
Upvotes: 2
Views: 2793
Reputation: 37494
Besides the custom URL scheme that the other answers mentioned, you could hack your way into this by storing the data encrypted within the fields of a temporary contact that you can create through the AddressBook API.
Upvotes: 0
Reputation: 75058
To expand a little on a response to Frank, I think you can use a custom URL with a file path - but I think the path you should use would be some place in the Caches directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
I am presuming other applications could see into this same space.
Upvotes: 0
Reputation: 49354
There's two ways to do it.
1) If you can encode your file as a string, you can pass it to another app via an NSURL
. The receiving app, "ReceivingApp" must implement the
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
in it's application delegate. Send your data using the
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"receivingapp://your.data.goes.here"]]];
2) Use the pasteboard.
I would use the custom URL scheme since it 1) will save you a few steps and 2) it doesn't give the rest of the OS access to your data should something go amiss with the receiving app. I'm not sure what the character limit on an NSURL is, but it's pretty big.
Upvotes: 9
Reputation: 25775
My understanding (although I could totally be wrong about this) is that apps can access the files of other apps, but that finding them is the problem, since each app's directory is assigned a new UUID as it's installed, and apps can't list the contents of the /Applications directory.
If you're writing both apps yourself you may be able to pass the location of one app's file to the other app using a custom URL scheme. Also if the file is sufficiently small, you could pass it as part of the URL.
Upvotes: 1
Reputation: 5803
The iPhone SDK has no officially-sanctioned shared repository — every app is sandboxed. If data can't be passed with a URL scheme, then it must be done through "the cloud". Stanza got around this by storing some data in the DCIM folder (which holds the user's photos), but Apple forced them to remove the functionality just a few days ago.
There are rumors that we will get a new data store in the 4.0 SDK, but nothing solid.
Upvotes: 4