`
zani
  • 浏览: 349731 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

用私有framework监测手机使用的哪种类型的网络

 
阅读更多

用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);

        }

    }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics