用Class-dump工具dump目录/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/PrivateFrameworks下的SoftwareUpdateServices.framework,发现有SUNetworkMonitor类
NSBundle *b = [NSBundlebundleWithPath:
@"/System/Library/PrivateFrameworks/SoftwareUpdateServices.framework"];
if ( [b load] )
{
// load Class from STRING
Class NetworkMonitor = NSClassFromString(@"SUNetworkMonitor");
// alloc class
id _NetPointer = [[NetworkMonitor alloc] init];
// check if the class have the method currentNetworkType
if ( [_NetPointer respondsToSelector:@selector(currentNetworkType)] )
{
int t = (int)[_NetPointer 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);
}
}