在Objective C中检查Internet连接 [英] Checking For Internet Connectivity in Objective C

查看:89
本文介绍了在Objective C中检查Internet连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究斯坦福iPhone编码课程,目前正在使用Twitter API。我想要做的是准确处理两个错误条件:一个用于用户名无效,另一个用于当设备当前未连接到互联网时。不幸的是,就目前而言,我能猜测的最好的是API的回报是否为零 - 两种情况都属于这种情况。

I've been working through the Stanford iPhone Coding course and currently hooking into the Twitter API. What I'd like to do is accurately handle two error conditions: One for when the username is invalid, and another for when the device is not currently connected to the internet. Unfortunately, as it stands, the best I can surmise is whether or not the return from the API is nil or not - which is the case for both conditions.

我是什么我正在寻找可以在尝试任何远程数据获取之前检查连接的一行或两行代码。我可以通过Apple文档进行筛选,但我想:为什么不把这个问题提交给你们,为了我的利益,或许是其他人的呢?

What I'm looking for is a line or two of code that can check for a connection before attempting any fetch of remote data. I could sift through the Apple documentation but I figured: Why not put the question to you guys for my benefit and perhaps that of others?

其他信息:使用Objective-C和XCode中的iPhone SDK。

Additional info: Using Objective-C and the iPhone SDK in XCode.

推荐答案

看看Apple的示例代码。 Reachability项目显示了如何检测连接。

Take a look at Apple's sample code. The Reachability project shows how to detect a connection.

http://developer.apple.com/iphone/library/samplecode/Reachability/index.html

这篇关于在Objective C中检查Internet连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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