Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Apps sharing documents directories

Tags:

ios

iphone

Is it possible for two applications to access documents in each other applications given that they have the same bundle seed id. I know that it is possible to share items in the keychain with applications that share a bundle seed id (see here).

For example, let's say you had an application that had a free version and a paid version. Is it possible that after someone has upgraded from the free to the paid version you could migrate their data over to the paid version?

like image 842
DHamrick Avatar asked Nov 11 '11 16:11

DHamrick


People also ask

Can you share file folders on iPhone?

Invite more people to share a folder or fileTouch and hold the folder or file. , then tap Manage Shared Folder or Manage Shared File. Tap Add People and choose a method for sending the link. Enter any other requested information, then send or post the invitation.

Does Apple have a File Sharing app?

iCloud Drive lets you securely access all of your documents from your iPhone, iPad, iPod touch, Mac, or PC. No matter which device you're using, you'll always have the most up-to-date documents when and where you need them.


1 Answers

You cannot share document directories between applications. But there are other communication channels open.

The keychain is one possibility, as you mentioned.

Another could be custom URL schemes. Maybe a bit like this:

  1. The free app registers the ability to open URLs with the freeapp:// scheme. Similarly the pro app registers the ability to open URLs with the proapp:// scheme. Use the "URL Types" entry in the info plist.
  2. Pro app checks if [UIApplication canOpenURL:@"freeapp://goPro"] == YES
  3. If true the pro app calls [UIApplication openURL:@"freeapp://goPro"]
  4. This launches the free app which must implement handleOpenURL from UIApplication.
  5. The free app packages the necessary data together in a URL. You can use HTTP-like parameters if you like. You can also build a dictionary and serialize it to a long hex-string using NSCoding.
  6. The free app passes the data back to the pro app using [UIApplication openURL:@"proapp://YOUR_DATA_IN_WHATEVER_FORMAT"]
  7. The pro app receives the URL in its overridden implementation of handleOpenURL from UIApplication and performs the necessary data migration.

Obviously you want to use more unique URL schemes than the above.

Consider the security implications of being able to inject this type of data into your app using URLs, though. It's probably OK for many purposes, but I'm sure that if the Facebook app provided a way to nuke your account settings via a URL some people would find it hilarious to post facebookapp://reset_my_account links everywhere.

Bonus tip: URL schemes are also very handy for bridging the gap between native code and web views. I have had a few apps with an embedded web view showing a page on a server under my control. The web page can talk to the app by setting the document location from JS. The app can intercept the request in the web view delegate and talk back to the web view using stringByEvaluatingJavaScriptFromString.

like image 153
Heiberg Avatar answered Sep 28 '22 02:09

Heiberg