【问题标题】:iPhone NetworkReachability - Tethering is recognised as 3G and not WIFIiPhone NetworkReachability - 网络共享被识别为 3G 而不是 WIFI
【发布时间】:2017-07-26 13:47:34
【问题描述】:

在我的应用中,我尝试使用 NetworkReachability 获取网络状态。我在 wifi 或 3g 连接下尝试过,效果很好。

问题是,当我连接到个人热点/网络共享(使用 iPhone 到 iPhone、Android 到 iPhone 和带 SIM 卡的路由器进行测试)时,我总是得到 3g 连接而不是wifi。用ios10测试。有什么办法不使用私有框架来控制我是否处于网络共享连接或热点?

【问题讨论】:

  • 你提到 NetworkReachability,没有人真正知道它到底是什么。

标签: ios objective-c iphone wifi tethering


【解决方案1】:

您已检查互联网可达性,使用以下链接从 Apple 下载可达性演示项目:

https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html

,并将 .h 和 .m 文件添加到您的项目中。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil];

reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];

- (void) handleNetworkChange:(NSNotification *)notice
{

  NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

   if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); }
}

【讨论】:

    【解决方案2】:

    GitHubAFNetworking 库中提供检查网络可达性状态。使用Network Reachability Manager对象文件检测网络可达状态。

    共享网络可达性

    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
    }];
    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      相关资源
      最近更新 更多