确定 iPhone 是真正连接到互联网还是仅在受限热点后面 [英] Determine whether iPhone is really connected to the internet or just behind a restricted hotspot

查看:15
本文介绍了确定 iPhone 是真正连接到互联网还是仅在受限热点后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在严格识别 iPhone 的网络访问类型方面遇到了很多麻烦.我在 StackOverflow 上看到过很多这样的问题,但没有一个对我有帮助.例如我已经看到了这个:如何在 iOS 或 OSX 上检查活动的 Internet 连接?

I'm having quite a lot of trouble on identifying rigorously the kind of network access an iPhone has. I have seen many questions like this one on StackOverflow but none of them helped me. For example I have already seen this: How to check for an active Internet connection on iOS or OSX?

但我想确切知道以下 3 种情况何时发生:

But I want to know precisely when the 3 following cases occur:

  1. Wifi 3G 已禁用

Wifi 3G 已启用,但没有没有互联网连接.这可能是由于 3G 没有真正工作,即使它显示在状态栏上,或者 WiFi 是在让您访问 Internet 之前要求登录的热点或最后一个场景:WiFi 源是本地网络,但确实不提供任何互联网连接.

Wifi or 3G are enabled but there is no internet connection. It could be due to 3G not really working, even though it is showing up on the status bar, or the WiFi is a hotspot asking to log in before letting you access the Internet or last scenario: The WiFi source is a local network but does not provide any Internet connection.

一切正常

当然,我尝试过各种各样的东西,例如:

Of course I have tried various stuff, like this for instance:

// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];

// Set the blocks
reach.reachableBlock = ^(Reachability*reach)
{
    /* NOT REACHABLE */
    dispatch_async(dispatch_get_main_queue(), ^{
        iarcSBInternetWarning.visible = NO;
    });
};

reach.unreachableBlock = ^(Reachability*reach)
{
    /* REACHABLE */
    iarcSBInternetWarning.visible = YES;
};

// Start the notifier, which will cause the reachability object to retain itself
[reach startNotifier];

但这似乎只是表示 Wifi 或 3G 是否已启用,并且不会检查可能的互联网限制.如果任何答案能帮助我确定这三种情况,我都会非常高兴.

But this seems just to say wether Wifi or 3G are enabled and does not check for possible internet restrictions. I would be highly delighted by any answer helping me identifying the three scenarios.

当然,分析来自返回特定字节序列的个人服务器 API 的直接 HTTP 请求输出是可行的,但这不是我想做的.我更喜欢使用任何类型的可达性 API.

Of course analyzing a direct HTTP request output from a personal server API returning a specific byte sequence would work but that is not what I would like to do. I'd prefer using any kind of Reachability API.

我使用了 Apple 的可达性 API,它似乎无法识别热点重定向.

I've used Apple's reachability API, it does not seem to recognize hotspot redirections.

如果使用 Reachability API 无法做到这一点,那么向服务器发出简单请求的最低资源消耗方法是什么,请检查它在指定的超时之前是否可以访问,以及 URL 是否未重定向到热点登录页面(可能只检查标题,而不是整个服务器字节序列输出)?每 15 秒运行一次这样的脚本是个好主意,还是会消耗过多的电池和/或网络数据?

If this is not possible with the Reachability APIs, then what would be the lowest resource-consuming method to make a simple request to a server, check that it is reachable before a specified timeout, and that the URL was not redirected to a hotspot login page (maybe only check the headers, not the whole server byte sequence output)? Is it a good idea to run such a script every 15 seconds, or would it use too much battery and/or network data?

推荐答案

检查出站连接最简单的方法是 GET Google 的 generate204 页面并检查响应代码

The simplest method to check outbound connectivity is to GET Google's generate204 page and check the response code

http://www.google.com/generate_204

或者你可以使用

http://www.apple.com/library/test/success.html 这是操作系统使用的页面

http://www.apple.com/library/test/success.html which is the page the OS uses

这篇关于确定 iPhone 是真正连接到互联网还是仅在受限热点后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆