How to determine whether user is on Edge or 3G on iPhone

前端 未结 4 1154

Though it is relatively straightforward to determine if an iPhone is on Wifi or a data network programmatically in your application, I can\'t figure out a way to determine i

4条回答
  •  执念已碎
    2020-12-18 02:52

    Try checking it from the status bar:

    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;
        }
    }
    int connectivity;
    connectivity =  [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
    

提交回复
热议问题