【问题标题】:How to detect network type i.e. 3G/4G? [duplicate]如何检测网络类型,即 3G/4G? [复制]
【发布时间】:2013-07-11 14:48:59
【问题描述】:

我正在开发一个应用程序,它将使用 WiFi 以及 iPhone 的蜂窝数据调用 Web 服务。我的应用程序在 WiFi 和 3G 网络上运行良好,但在 4G 网络上无法运行。所以请告诉我如何检测应用程序是通过 3g 还是 4G 连接以及如何解决与 4G 网络相关的问题。

任何帮助都将不胜感激。 提前致谢。

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    这里是同样的问题,下面的示例代码可能对您有所帮助。使用私有 API,您可以直接在状态栏中读取此信息。

    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"];
    }
    

    功劳归于:-

    Determining 3G vs Edge

    Objective-C determine data network type of the iOS device

    【讨论】:

    • 我的应用在后台时需要这个结果
    • @Nitin Gohel,我认为这是一个私有 api,所以可能会被苹果拒绝。是否使用上述代码通过苹果批准您的应用程序?请建议我,以便我在将应用程序上传到苹果商店之前对此有所了解。
    • 嗡嗡声可能是现在苹果方面的变化太多了
    • 使用私有 API 不是一个好建议,它并没有真正解决问题。问题的根源在于弄清楚为什么它在 4G 上不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2017-04-19
    • 2023-03-07
    相关资源
    最近更新 更多