iOS 可达性指南 [英] Reachability Guide for iOS

查看:34
本文介绍了iOS 可达性指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 框架添加到您的项目中.#import "Reachability.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屋!

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