确定iPhone是否确实已连接到Internet或仅在受限制的热点之后 [英] Determine whether iPhone is really connected to the internet or just behind a restricted hotspot

查看:163
本文介绍了确定iPhone是否确实已连接到Internet或仅在受限制的热点之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在严格确定iPhone的网络访问类型方面,我遇到了很多麻烦.我在StackOverflow上看到了很多类似的问题,但是没有一个对我有帮助.例如,我已经看到了以下内容:如何在iOS或OSX上检查互联网连接是否有效?

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,但没有没有 Internet连接.可能是由于3G不能正常工作,即使它显示在状态栏上,还是WiFi是一个热点,要求登录后才允许您访问Internet或最后一种情况:WiFi源是一个本地网络,但确实不提供任何Internet连接.

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,并且未将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?

推荐答案

检查出站连接的最简单方法是获取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是否确实已连接到Internet或仅在受限制的热点之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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