适用于iOS的可达性指南 [英] Reachability Guide for iOS
问题描述
有没有人找到在iOS上实现可达性的中途指南?
Has anyone found a halfway decent guide to implementing Reachability on iOS?
推荐答案
我已经实现了这样的Reachability。
下载 https://developer.apple.com /library/content/samplecode/Reachability/Introduction/Intro.html 并将Reachability.h和.m添加到您的项目中。将SystemConfiguration框架添加到项目中。 #importReachability.h您要使用它。使用此代码。
I have implemented Reachability like this. Download https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html and add Reachability.h and .m to your project. Add the SystemConfiguration framework to your project. #import "Reachability.h" where you want to use it. Use this code.
-(BOOL)reachable {
Reachability *r = [Reachability reachabilityWithHostName:@"enbr.co.cc"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if(internetStatus == NotReachable) {
return NO;
}
return YES;
}
当你想检查可达性时......
When you want to check for reachability...
if ([self reachable]) {
NSLog(@"Reachable");
}
else {
NSLog(@"Not Reachable");
}
这是我做的示例项目。 http://dl.dropbox.com/u/3656129/ReachabilityExample.zip
Here is the example project that I made. http://dl.dropbox.com/u/3656129/ReachabilityExample.zip
这篇关于适用于iOS的可达性指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!