Domanda

Hi i need to find out whether iPhone internet connected 3G or 2G or WIFI network any suggestions

Thanks

Sravan

È stato utile?

Soluzione

Download Reachability Class for iOS from this link:- https://github.com/tonymillion/Reachability

1)Add Reachability.h &.m in your Project, make sure you make it ARC compatible by adding flag -fno-objc-arc

2)Now, check the connection type in your view controller

  Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus status = [reachability currentReachabilityStatus];

    if(status == NotReachable) 
    {
        //No internet
    }
    else if (status == ReachableViaWiFi)
    {
        //WiFi
    }
    else if (status == ReachableViaWWAN) 
    {
        //3G
    }

Altri suggerimenti

You can use the Reachability library written by tonymillion. If you don't wan to use ARC, there is also the Apple Reachability library.

Also take a look inside of < CoreTelephony/CTTelephonyNetworkInfo.h >

You will see that there is a currentRadioAccessTechnology property exposed on CTTelephonyNetworkInfo.

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
NSLog(@"Radio access technology:\n%@",
       netInfo.currentRadioAccessTechnology);

You can subscribe to changes via:

[NSNotificationCenter.defaultCenter
    addObserverForName:CTRadioAccessTechnologyDidChangeNotification
                object:nil
                 queue:nil
            usingBlock:^(NSNotification __unused *notification) {
                CTTelephonyNetworkInfo *current =
                    [[CTTelephonyNetworkInfo alloc] init];
                NSLog(@"Updated Radio access technology:\n%@",
                       current.currentRadioAccessTechnology);
            }];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top