你如何在手机游戏中检测3G与Wifi连接? [英] How do you detect 3G vs. Wifi connection on mobile safari?

查看:160
本文介绍了你如何在手机游戏中检测3G与Wifi连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我特意询问移动网页上的javascript,而不是Objective-c应用程序。有没有类似Apple的Reachability for javascript所以我可以告诉Edge,3G或Wifi连接何时发生或更改?

I am specifically asking about javascript on a mobile webpage, not an objective-c application. Is there something like Apple Reachability for javascript so I can tell when Edge, 3G or Wifi connection is made or changed?

推荐答案

不除非浏览器开始通过DOM提供这些信息,而目前他们没有。有一个导航器 javascript对象,它包含许多内容,但不包含您要查找的内容。我最近还在新闻中看到,一些移动运营商正在为手机上的HTTP请求添加cookie。他们被发现将客户ID添加到cookie中(巨大的安全漏洞!!)。

Not unless browsers start giving this information away through the DOM which, currently, they don't. There is a navigator javascript objects which holds many things but not what you're looking for. I've also read in the news recently that some cellular carrier was adding cookies to HTTP requests made on their phones. They were found to be adding customer IDs to cookies (huge security breach!!).

Mobile Safari确实添加了一些新的 DOM添加但不是你的内容要求。

Mobile Safari does add some new DOM additions but not what you're asking for.

除了这些选项,你不能。互联网协议的各层旨在封装和隐藏底层的细节。您无法检测到Edge,3G或Wifi,因为您可以检测到有线,DSL或更精细的光学器件。

Short of these options, you can't. Layers of the Internet Protocol are meant to encapsulate & hide the details of the bottom layers. You can't detect Edge, 3G or Wifi any more than you can detect cable, DSL or finer optics.

最后,即使你可以获取此信息,除非您在TCP连接中有每个节点的详细信息,否则对您没有任何帮助。例如,我可以进行以下设置:

Finally, even if you could get this information, it wouldn't do you any good unless you had details of every single node in your TCP connection. For example, I could have the following setup :

iPad  ---WiFi---->  iPhone's Hotspot  ---3G--->  Carrier ---unknown--->>>






附录



2012-2013, W3C 正在充实网络信息API ,旨在提供Web应用程序访问设备底层连接信息的接口的。 当时,API规定浏览器的估计带宽可通过 navigator.connection.bandwidth 获得。 截至2014年4月,此项工作已停止!!


Addendum

In 2012-2013, the W3C was fleshing out The Network Information API which was aimed at providing "an interface for web applications to access the underlying connection information of the device". At the time, the API stipulated that an "estimated" bandwidth for the browser would be obtainable via navigator.connection.bandwidth. As of April 2014, that work has since been discontinued!!

更新:截至2015年10月20日,这个API继续工作。您可以在W3C的github页面上找到最新的编辑网络信息API草案

Update: As of 20th October 2015, work continues on this API. You can find the latest Editor's drafts for the Network Information API on the W3C's github pages.

这篇关于你如何在手机游戏中检测3G与Wifi连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆