0

I send emails to my iOS customers with links to our app. When they tap the link, I want to check if they have the app installed.

If the app is installed I want to open it. If not it will redirect to download the app in the App Store.

The URL I'm using to open the app is:

rva://store?uuid=EFBBD9FF-3976-4816-8B77-C1462C99E256

And the check I was using is:

def responds_to_url?(url)
  response = Net::HTTP.get_response(URI(url)).code
  if response == "200"
    return true
  else
    false
  end
end

The problem is that passing my URL above to URI() returns a Generic (capital G) URI object, whereas it should (if it were http) return an HTTP object.

How can I do a similar check with just a link (i.e. no javascript)?

I thought about passing the URL to Mobile Safari and seeing if it responds, but I don't know how to do that or even if it's possible.

Trevor McKendrick
  • 595
  • 2
  • 7
  • 27
  • Did you try to detect devise by UserAgent? – Ivan Shamatov Dec 18 '13 at 08:53
  • Unfortunately even with an identical UserAgent the URL will respond with 200 on some devices but not on others. Please see my response to Pete below. – Trevor McKendrick Dec 18 '13 at 08:59
  • I don't understand the question. How can device respond to link? They just send request and then receive it. There is no response from device. – Billy Chan Dec 18 '13 at 09:29
  • Good point. Some of my URLs are deep links to iOS apps. If the device has the app (i.e. doesn't return an error in Safari saying "Safari cannot open the page because the address is invalid.") I want the app to open. Otherwise I want to redirect to an actual http request. I should have mentioned all this earlier, hope it clarifies. – Trevor McKendrick Dec 18 '13 at 09:35
  • I know little about iOS. I wonder if Mobile Safari has such API to check if specific app is on this device and open it. If that's true, I guess you can send just one response, with Javascript to call that API with timeout and html words saying waiting. Within the timeout say 3 seconds, if device can open app, that's good. If not, timeout, the page will show "It looks you don't have Foo app installed. We suggest you to install **here**, or continue browsing **here**(Or auto redirect). Not 100% automatic but should be user friendly enough. – Billy Chan Dec 18 '13 at 10:02

2 Answers2

1

You could do client browser detection with HTTP_USER_AGENT, I believe there is a gem for that: Rails Browser Detection Methods

Community
  • 1
  • 1
Pete
  • 76
  • 5
  • It's not specific to the browser though. It's specific to the device on which the browser resides. – Trevor McKendrick Dec 18 '13 at 08:58
  • @TrevorMcKendrick User agent will show the device too. See this for example: http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader – Enrico Susatyo Dec 18 '13 at 10:07
  • I can't use User agent because identical User agents will respond differently depending on whether the app is installed on the user's device. – Trevor McKendrick Dec 18 '13 at 16:26
  • Sorry Trevor, I misunderstood your earlier question. Your Rails app plays no role in the action of the user following an iOS protocol link in an email. I'd suggest you insert a plain http link to an intermediary webpage in the e-mail. This page will detect a cookie if your user has installed the app and instantly redirect them to the eva://store uri. If the cookie is not detected the user will see the 2 options a) launch the app if they know they have it installed (you can now set that cookie for future attempts and redirect the app url). b) go to your app in the App Store Beware Apple Ts&Cs – Pete Dec 19 '13 at 08:36
0

What you describe is not possible. Your rails app will have very limited knowledge of the client—mostly in the form of the User Agent—and there is no way for your Rails app to query for more information while handling a request.

Amanda Mitchell
  • 2,665
  • 1
  • 16
  • 23