Determining 3G vs Edge

后端 未结 5 1126
青春惊慌失措
青春惊慌失措 2020-11-27 03:08

I know that the reachability example allows detection of whether network is accessible via Wifi or Cell, but is there a way to determine whether the cell connection is over

5条回答
  •  情话喂你
    2020-11-27 03:51

    Marginally simplified version of nst's code to silence compiler warnings I got in XCode 4.5:

    - (NSNumber *) dataNetworkTypeFromStatusBar {
    
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"]    subviews];
        NSNumber *dataNetworkItemView = nil;
    
        for (id subview in subviews) {
            if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
                dataNetworkItemView = subview;
                break;
            }
        }
        return [dataNetworkItemView valueForKey:@"dataNetworkType"];
    }
    

    And the value keys I've found so far:

    • 0 = No wifi or cellular
    • 1 = 2G and earlier? (not confirmed)
    • 2 = 3G? (not yet confirmed)
    • 3 = 4G
    • 4 = LTE
    • 5 = Wifi

提交回复
热议问题