判断网络是否可用
1. 从官网例子Reachability中copy Reachability.h和Reachability.m
2. 添加Systemconfiguration.framework
3. 使用下列方法
Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch ([r currentReachabilityStatus]) {
case NotReachable:
// 没有网络连接
NSLog(@"没有网络");
break;
case ReachableViaWWAN:
// 使用3G网络
NSLog(@"正在使用3G网络");
break;
case ReachableViaWiFi:
// 使用WiFi网络
NSLog(@"正在使用wifi网络");
break;
}
warning: declaration of 'struct sockaddr_in' will not be visible outside of this function [3]
+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;
解决:在Reachability.h中添加#import <netinet/in.h> // sockaddr_in