2

I'm wondering if there is a way to open an app when clicking on a link in safari (or other browser) in iOS.

My app posts the name of a location, a screenshot on Twitter/Facebook which also has a link. I need to detect when the user clicks that link if he is on a pc or iOS device. If they're not on iOS device I want to continue to the linked page otherwise I want to open the app and also take take that location name as a parameter when opening it.

Jessedc
  • 12,320
  • 3
  • 50
  • 63
Poppy Deejay
  • 75
  • 1
  • 8

1 Answers1

6

If the app has registered a custom URL scheme the device will open the particular app when it's asked to open a URL of a particular scheme.

This stems from the CFBundleURLSchemes key of your apps infoPlist. Apple's documentation has all the information you need to get started.

To register a URL type for your app, include the CFBundleURLTypes key in your app’s Info.plist file. The CFBundleURLTypes key contains an array of dictionaries, each of which defines a URL scheme the app supports. Table 6-2 describes the keys and values to include in each dictionary.

See more here at the iOS Programming Guide: Advanced App Tricks under 'Communicating with Other Apps' section.

Edit

In order to support the specific functionality of your question you need to go one step deeper.

  1. Your first link needs to be a standard web URL.
  2. The page presented from the first URL needs to detect the device and forward the user onto a second URL that will open the app on the device, with whatever parameters you want to forward to the app.

So - what you're going to have to do is build some sort of device detection into the page that your first URL points to. On that page, detect the device, then conditionally forward the user onto the second URL that will be the custom URL of your particular app.

It's possible to do this device detection, and detect if they have the app installed on their device with some of the newer HTML5 features supported by mobile browsers, but your question is themed around opening apps with URLs in iOS and the main native iOS hooks you need to support opening apps (with parameters and all) is in the documentation above.

Community
  • 1
  • 1
Jessedc
  • 12,320
  • 3
  • 50
  • 63
  • okay i got that but how to i get that location name from that post , is it even possible to do that? – Poppy Deejay Aug 20 '12 at 12:55
  • @PoppyDeejay I've updated my answer to give some more details on how to approach a solution, but some of what you might need to do falls out of the bounds of this one question. – Jessedc Aug 20 '12 at 13:15
  • yes thank you for your answer, the only thing i needed to do is just set-up the custom url scheme and add the handleOpenURL function to the delegate, and add a javascript to that page that handles the detection of betweeen pc and iOS. ( if pc go to the http:// site else go to the myapp://params – Poppy Deejay Aug 20 '12 at 16:30
  • @PoppyDeejay Yep, I that's the gist of it. – Jessedc Aug 20 '12 at 22:51