如何在IOS中检查网络2G或3G? [英] How to check network 2G or 3G in IOS?

查看:98
本文介绍了如何在IOS中检查网络2G或3G?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查设备是否有2G或3G连接。

I want to check if the device has a 2G or 3G connection.

我使用Reachability类进行网络连接检查。

I used Reachability class for network connection check.

推荐答案

在iOS 7中,Apple提供了一种获取它的新方法。

In iOS 7 Apple provided a new way to get it.

请阅读此链接。 了解你的电台部分。

Please read this link. The "Know your Radio" section.

基本想法是使用新的


currentRadioAccessTechnology

currentRadioAccessTechnology

添加到CTTelephonyNetworkInfo类。如果您希望每次连接更改时收到通知,您可以收听:

added to the CTTelephonyNetworkInfo class. If you want to get notified everytime the connection changes you can listen for:


CTRadioAccessTechnologyDidChangeNotification

CTRadioAccessTechnologyDidChangeNotification

下面是从提供的链接中获取的代码片段:

Heres a code snippet took from the provided link:

CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification 
                                            object:nil 
                                             queue:nil 
                                        usingBlock:^(NSNotification *note) 
{
    NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];

我希望这会对你有所帮助。

I hope this helps you.

这篇关于如何在IOS中检查网络2G或3G?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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