Check if your iOS device’s internet connection is working properly.

There are many questions about finding an active Internet connection in the application, but no one works if you use a 3g connection and you do not have access to data, or if you are on a WiFi network in a hotel, which is automatically redirected to the login page, and you are not yet entering a password. Such situation.

What is the fastest way to check if your internet connection is working?

+4
source share
2 answers

You can use the AFNetworkReachabilityManager class in AFNetworking .

https://github.com/AFNetworking/AFNetworking

. . :

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

[[AFNetworkReachabilityManager sharedManager] startMonitoring];
0

, Reachability API, - NSURL . - 20 .

- (void)checkConnection //Run this on a side queue, never on a main queue
{    NSURL *checkURL = [NSURL URLWithString:@"http://www.apple.com"];

    NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:checkURL]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:20.0];

    NSData *data = [NSData dataWithContentsOfURL:lRequest];

    if (data)
    {
        connected = YES;
    }
    else
    {
        connected = NO;
    }
}

, -, -, .

, / ! , .

-1

Source: https://habr.com/ru/post/1606135/


All Articles