适用于iOS的可达性指南

esq*_*qew 43 iphone reachability ios

有没有人找到在iOS上实现Reachability的中途体面指南?

enb*_*nbr 95

我已经实现了这样的Reachability.下载https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html并将Reachability.h和.m添加到您的项目中.将SystemConfiguration框架添加到项目中.#import"Reachability.h"您要使用它.使用此代码.

-(BOOL)reachable {
    Reachability *r = [Reachability reachabilityWithHostName:@"enbr.co.cc"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    if(internetStatus == NotReachable) {
        return NO;
    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

当你想检查可达性时......

if ([self reachable]) {
    NSLog(@"Reachable");
}
else {
    NSLog(@"Not Reachable");
}
Run Code Online (Sandbox Code Playgroud)

这是我做的示例项目.http://dl.dropbox.com/u/3656129/ReachabilityExample.zip