如何检测用户是否通过JavaScript安装了特定的iPhone应用程序?

时间:2021-07-21 01:22:07

I'd like to build a mobile Web app that:

我想构建一个移动Web应用程序:

  • If my iPhone app is already installed, launches it by redirecting to a URL handled by the app
  • 如果我的iPhone应用程序已经安装,请通过重定向到应用程序处理的URL来启动它
  • If my iPhone app is not installed, displays a web page encouraging users to download it from the App Store
  • 如果未安装我的iPhone应用程序,则会显示一个网页,鼓励用户从App Store下载

The problem is, I don't know how to detect whether the app is installed before redirecting. Does anyone know a trick for doing this? Maybe a JavaScript hack of some sort, leveraging the App registered URL in an iframe or similar?

问题是,我不知道在重定向之前如何检测应用程序是否已安装。有没有人知道这样做的诀窍?也许是一种JavaScript破解,利用iframe或类似的App注册URL?

1 个解决方案

#1


0  

You very likely can't do this. Even in a native app, all you can call is UIApplication's canOpenURL: method, which just tells you if some app will open the URL, not which one. I have no idea if this function is exposed in JavaScript; very likely not (I wouldn't want malicious javascript probing my phone for which URLs it can open).

你很可能不能这样做。即使在本机应用程序中,您可以调用的只是UIApplication的canOpenURL:方法,它只会告诉您某个应用程序是否会打开URL而不是哪个应用程序。我不知道这个函数是否在JavaScript中公开;很可能不是(我不希望恶意javascript探测我的手机可以打开哪些网址)。

#1


0  

You very likely can't do this. Even in a native app, all you can call is UIApplication's canOpenURL: method, which just tells you if some app will open the URL, not which one. I have no idea if this function is exposed in JavaScript; very likely not (I wouldn't want malicious javascript probing my phone for which URLs it can open).

你很可能不能这样做。即使在本机应用程序中,您可以调用的只是UIApplication的canOpenURL:方法,它只会告诉您某个应用程序是否会打开URL而不是哪个应用程序。我不知道这个函数是否在JavaScript中公开;很可能不是(我不希望恶意javascript探测我的手机可以打开哪些网址)。