I have two iPhone apps that I've built that have their own custom URLs and are in the app store. Let's call them App A and App B.

App A's interface is a UIWebView that gets its markup from a remote server that I run. The behavior I want to implement in app A is this:

  • If a link is generated with the custom URL for App B, and App B is installed on the device, open App B. This is easily done by checking UIApplication canOpenURL: and, if it returns YES, calling UIApplication openURL:.

  • If a link is generated with the custom URL for App B, and App B is not installed on the device, go to the app store page for App B.

Here is how I plan on handling that second one:

  • Include a URL parameter in the custom URL that contains the link to the app store page for App B. If canOpenURL: returns NO for the whole URL, open the URL specified by that parameter instead.

That should work. But it feels a bit hacky because it means App A has to know how to parse the custom URL for App B to retrieve the alternate link. That seems to be less-than-ideal encapsulation. Is there some other convention I should be using to provide the failover URL when canOpenURL: returns NO?

有帮助吗?

解决方案

Will you always be opening these URLs for AppB from within AppA?

If so, then why do you need to add the link to the App Store page for AppB in the URL?

Why can't AppA already "know" the App Store URL for AppB, and if "canOpenURL" returns NO for the Custom URL Scheme, then it will just send the user to that App Store page?

This seems like a much cleaner solution.

PS: I know this is an old question, but the question has a couple of upvotes, and hasn't been answered, so perhaps this will help someone...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top