简体   繁体   中英

iOS Apps sharing documents directories

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM