【问题标题】:Detect iOS network permission of my app检测我的应用的 iOS 网络权限
【发布时间】:2017-05-05 07:11:33
【问题描述】:

从 iOS 10 开始,应用需要网络权限才能访问网络。
如何以编程方式检查我的应用是否设置为“关闭”或“WLAN”或“WLAN 和蜂窝数据”?

Screenshot of "Allow App TO USE DATA"

【问题讨论】:

    标签: ios networking permissions


    【解决方案1】:

    您可以使用可达性进行检查。

    Reachability *netReachability = [Reachability reachabilityForInternetConnection];
    [netReachability startNotifier];
    
    NetworkStatus networkStatus = [netReachability currentReachabilityStatus];
    
    if(networkStatus == NotReachable) 
    {
        //No internet connection.
    }
    else if (networkStatus == ReachableViaWiFi)
    {
        //connected with WiFi network.
    }
    else if (networkStatus == ReachableViaWWAN) 
    {
        //connected with 3G network.
    }
    

    希望这会有所帮助。

    【讨论】:

    • 感谢 Sachin,但我不认为可达性对此有用。
      例如,如果用户同时关闭 Wifi 和 Celluar,但将我的应用设置为允许访问“WLAN & Celluar Data”,则结果将是 NotReachable。
    • 你无法判断你的应用是否被明确拒绝网络访问,只能判断网络是否可达;这可能是因为您的应用已被拒绝网络访问或因为没有网络
    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 2021-01-12
    • 1970-01-01
    • 2018-11-23
    • 2021-05-03
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    相关资源
    最近更新 更多