如果安装了我的iPhone应用程序,如何通过Safari Mobile中的javascript检测?

时间:2023-01-05 07:16:00

As you probably know, iPhone applications can register a custom URL scheme handler, ala "myapp:" and these can be used for links in a page viewed in Safari.

您可能知道,iPhone应用程序可以注册自定义URL方案处理程序,ala“myapp:”,这些可以用于在Safari中查看的页面中的链接。

I'd like to automatically launch my application from a specific page if the visitor has the app installed. If the app's not installed, I'll just show them the current mobile-optimized view of the page.

如果访问者安装了应用程序,我想从特定页面自动启动我的应用程序。如果未安装应用程序,我只会向他们展示当前针对移动设备优化的页面视图。

How can I do this detection? Google searches have been fruitless. Also, to be tricky, I've tried doing something like this to no avail:

我该怎么做这个检测?谷歌的搜索毫无结果。另外,为了变得棘手,我尝试过做这样的事情无济于事:

var image = new Image();
image.onerror = function(e){
  alert("bummer");
}
image.onload = function(e){
  alert('success!');
}
image.src = 'myapp://something=meaningful';

Has anyone come across a way to do application detection?

有没有人遇到过应用程序检测的方法?

2 个解决方案

#1


6  

The solution I've presented on another Stack Overflow question is about as close as you're going to get.

我在另一个Stack Overflow问题上提出的解决方案就像你将要获得的那样接近。

#2


0  

I don't think this is possible. You would need to register your app on the iPhone/Mobile Safari and then create a uri to fire your app up, just like http:, ftp: mailto:. So in your case you would have something like Am I installed Mobile Safari would need to know what app to fire up to load that URI and I just don't think this functionality is built into the iPhone. I know there is no way javascript can query your iPhone to see what's installed.

我不认为这是可能的。您需要在iPhone / Mobile Safari上注册您的应用程序,然后创建一个uri来启动您的应用程序,就像http:,ftp:mailto:。所以在你的情况下,你会有类似的东西,我安装Mobile Safari需要知道要启动哪个应用程序加载该URI,我只是不认为这个功能是内置在iPhone中。我知道javascript无法查询你的iPhone以查看安装的内容。

I hope I am wrong as this seems like it would be a powerful feature, though on the other side I can see some security issues related to something like this.

我希望我错了,因为这似乎是一个强大的功能,但另一方面我可以看到一些与此类相关的安全问题。

Good luck.

祝你好运。

#1


6  

The solution I've presented on another Stack Overflow question is about as close as you're going to get.

我在另一个Stack Overflow问题上提出的解决方案就像你将要获得的那样接近。

#2


0  

I don't think this is possible. You would need to register your app on the iPhone/Mobile Safari and then create a uri to fire your app up, just like http:, ftp: mailto:. So in your case you would have something like Am I installed Mobile Safari would need to know what app to fire up to load that URI and I just don't think this functionality is built into the iPhone. I know there is no way javascript can query your iPhone to see what's installed.

我不认为这是可能的。您需要在iPhone / Mobile Safari上注册您的应用程序,然后创建一个uri来启动您的应用程序,就像http:,ftp:mailto:。所以在你的情况下,你会有类似的东西,我安装Mobile Safari需要知道要启动哪个应用程序加载该URI,我只是不认为这个功能是内置在iPhone中。我知道javascript无法查询你的iPhone以查看安装的内容。

I hope I am wrong as this seems like it would be a powerful feature, though on the other side I can see some security issues related to something like this.

我希望我错了,因为这似乎是一个强大的功能,但另一方面我可以看到一些与此类相关的安全问题。

Good luck.

祝你好运。