0

I wanted to know the way to decide whether my device is on 3G or GPRS/4G network. Especially whether it uses 3G connection or not? Is there any way to do it programmatically?

Also, I wanted to enable and disable 3G programmatically?

It will be fine even if private API is suggested.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tanu
  • 303
  • 1
  • 2
  • 13

2 Answers2

1

If you don't mind using private APIs (Apple will reject this if you want to sell it on AppStore), You may use the code bellow. However it is little unstable on network change.

void *libHandle=dlopen("/System/Library/PrivateFrameworks/SoftwareUpdateServices.framework/SoftwareUpdateServices",RTLD_LAZY);

Class SUNetworkMonitor = NSClassFromString(@"SUNetworkMonitor");
NSObject *networkMonitor=[SUNetworkMonitor sharedInstance];

// check if the class have the method currentNetworkType
if ( [networkMonitor respondsToSelector:@selector(currentNetworkType)] )
{
    int t = (int)[networkMonitor performSelector:@selector(currentNetworkType)];

    NSString *type = @"";
    switch ( t ) {
        case 0:  type = @"NO-DATA"; break;
        case 1:  type = @"WIFI"; break;
        case 2:  type = @"GPRS/EDGE"; break;
        case 3:  type = @"3G"; break;
        default: type = @"OTHERS"; break;
    }

    NSLog(@"Network type: %@", type);
}
dlclose(libHandle);
1

Well I can take the first part of the Question.

There is sample in iOS Developer Library - Reachability Take a look at Reachability.m it indicates whether you have a connection and the kind of connection.

Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
  • ok.. I already looked at this code. It only tells me whether iPhone is using cellualr network or WI-FI. But in case of cellualr network, I am not getting which cellular network iPhone uses i.e. whether it uses 3G/GPRS/4G/EDGE network – Tanu Apr 25 '11 at 08:18
  • Can you suggest me way to get type of cellualr network. especially i am interested in knowing whether iPhone uses 3G or not – Tanu Apr 25 '11 at 08:19