Possible Duplicate:
How to check for an active Internet Connection on iPhone SDK?可能重复:如何在iPhone SDK上检查活动的Internet连接?
I need to check the internet reachability before sending a request to fetch something remotely. I googles, and found several SO questions relating to this. But i need to check internet connectivity for iOS4 and iOS5. How can i do that programatically ?
我需要在发送远程获取内容的请求之前检查互联网可达性。我谷歌搜索,并发现了几个与此有关的SO问题。但我需要检查iOS4和iOS5的互联网连接。我怎么能以编程方式做到这一点?
2.) For example say i am downloading a big file (when there was internet). and suddenly the Internet goes down (Then the app might crash). So how can i avoid this ?
2.)例如说我正在下载一个大文件(当有互联网时)。然后互联网瘫痪(然后应用程序可能崩溃)。那我怎么能避免这个呢?
1 个解决方案
#1
1
Download Reachability from Apple Site
从Apple站点下载可访问性
Reachability *reachability = [Reachability reachabilityForInternetConnection];
remoteHostStatus = [reachability currentReachabilityStatus];
if (remoteHostStatus != NotReachable) {
// do work here if the user has a valid connection
}
#1
1
Download Reachability from Apple Site
从Apple站点下载可访问性
Reachability *reachability = [Reachability reachabilityForInternetConnection];
remoteHostStatus = [reachability currentReachabilityStatus];
if (remoteHostStatus != NotReachable) {
// do work here if the user has a valid connection
}