Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone active network type (2G, 3G, WiFi)

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.

like image 570
mxg Avatar asked Oct 28 '09 12:10

mxg


People also ask

Does iPhone have 2G network?

Your Apple iPhone 13 Pro Max automatically joins the fastest data connection available. In some situations, you may want to switch to 2G, 3G or 4G. To manually select the connection type, follow these steps. Note: Enabling 4G on your device will allow you to benefit from faster data speeds and enhanced voice quality.

What is Wi-Fi active iPhone?

You can use Wi-Fi Assist with most apps like Safari, Apple Music, Mail, Maps, and more. When Wi-Fi Assist is activated, you'll see the cellular data icon in the status bar on your device. Because you'll stay connected to the Internet over cellular when you have a poor Wi-Fi connection, you might use more cellular data.


3 Answers

The SCNetworkReachability interface can help you with that. Basically, you create a so-called reachability reference and then call SCNetworkReachabilityGetFlags 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.

like image 109
Ole Begemann Avatar answered Sep 30 '22 19:09

Ole Begemann


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.

like image 36
mmc Avatar answered Sep 30 '22 19:09

mmc


This is the way to find the network mode(2G,3G,4G or wifi) of your device in swift.

if let reachability = Reachability.forInternetConnection() {

        reachability.startNotifier()

        let status = reachability.currentReachabilityStatus()

        if status == .init(0) {
            // .NotReachable

            print("Not Reachable")

        }
        else if status == .init(1) {
            // .ReachableViaWiFi

            print("Reachable Via WiFi")

        }
        else if status == .init(2) {
            // .ReachableViaWWAN
            let netInfo = CTTelephonyNetworkInfo()

            if let cRAT = netInfo.currentRadioAccessTechnology  {

                switch cRAT {

                case CTRadioAccessTechnologyGPRS,
                     CTRadioAccessTechnologyEdge,
                     CTRadioAccessTechnologyCDMA1x:

                    print("Reachable Via 2G")


                    do{
                        try realm.write {
                            realm.add(ModalDataSaver.singletonClass)
                        }
                    }catch
                    {
                        print("Error in saving data :- \(error.localizedDescription)")
                    }


                case CTRadioAccessTechnologyWCDMA,
                     CTRadioAccessTechnologyHSDPA,
                     CTRadioAccessTechnologyHSUPA,
                     CTRadioAccessTechnologyCDMAEVDORev0,
                     CTRadioAccessTechnologyCDMAEVDORevA,
                     CTRadioAccessTechnologyCDMAEVDORevB,
                     CTRadioAccessTechnologyeHRPD:

                    print("Reachable Via 3G")

                case CTRadioAccessTechnologyLTE:

                    print("Reachable Via 4G")

                default:

                    fatalError("error")

                }
            }
        }
    }
like image 25
Ayush jain Avatar answered Sep 30 '22 17:09

Ayush jain