Determining 3G vs Edge

后端 未结 5 1114
青春惊慌失措
青春惊慌失措 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:59

    Using private APIs, you can read this information directly in the status bar.

    https://github.com/nst/MobileSignal/blob/master/Classes/UIApplication+MS.m

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

提交回复
热议问题