iPhone 活动网络类型(2G、3G、WiFi)
有谁知道如何确定特定时刻的活动网络类型:2G、3G 或 WiFi。
例如,在特定时刻可能启用3G,但使用的网络类型可能是2G。
Does anyone know how to determine the active network type at the specific moment: 2G, 3G or WiFi.
For example, at a specific moment there could be enabled 3G, but the used network type could be 2G.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SCNetworkReachability
界面可以帮助您实现这一点。基本上,您创建一个所谓的可达性引用,然后对其调用SCNetworkReachabilityGetFlags
以获取有关连接的信息。返回的标志包括
kSCNetworkReachabilityFlagsIsWWAN
,它告诉您是通过 WiFi 还是蜂窝网络进行连接。但据我所知,它不能用来区分 2G 和 3G。有关实现,请参阅 Apple 的 Reachability 示例应用。在大多数情况下,您应该能够直接使用项目中包含的
Reachability
类。The
SCNetworkReachability
interface can help you with that. Basically, you create a so-called reachability reference and then callSCNetworkReachabilityGetFlags
on it to get information about the connection.The returned flags include
kSCNetworkReachabilityFlagsIsWWAN
, which tells you whether you are connected via WiFi or the cell network. AFAIK it cannot be used to tell the difference between 2G and 3G, though.See Apple's Reachability sample app for an implementation. In most cases, you should be able to directly use the included
Reachability
class in your project.转到 Apple 开发人员站点,下载一个名为“Reachability”的示例项目,
它提供了您想要执行的操作的示例。
值得注意的是,我不相信您能够区分 EDGE(2G) 和 3G 连接之间的区别。它是 WiFi 或 WWAN。
Go to the Apple Developer site, and download a sample project called "Reachability"
It provides an example of what you would like to do.
It is worth noting that I don't believe that you can tell the difference between EDGE(2G) and a 3G connection. It's either WiFi or WWAN.