怎么使用Reachability查询联网状态
1个回答
展开全部
(NSNotification *)notify {
Reachability *curReach = [notify object];
NetworkStatus networkStatus = [curReach currentReachabilityStatus]、关闭通知并释放对象
[[NSNotificationCenter defaultCenter] removeObserver;/有网络状态,3G或wifi
//
address;
if (networkStatus == NotReachable) { / :nil];
if (reachability) {
[reachability stopNotifier]1、注册通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityIsChanged:)
name;
[reachability startNotifier];
/
address;
reachability = [[Reachability reachabilityWithAddress;/无网络状态
//TODO
} else { :kReachabilityChangedNotification object:kReachabilityChangedNotification object.sin_family = AF_INET;
address.sin_port = htonl(IP_PORT);
address.sin_addr, sizeof(address));TODO
}
}
4:address] retain].sin_len = sizeof(address):self name.s_addr = htons(inet_addr(IP_Address));/开启网络检测
3、网络状态改变接受通知处理
-(void)reachabilityIsChanged;/关闭网络检测
[reachability release]:nil];
2、创建Reachability实例对象并开启通知
struct sockaddr_in address;
memset(address, 0
Reachability *curReach = [notify object];
NetworkStatus networkStatus = [curReach currentReachabilityStatus]、关闭通知并释放对象
[[NSNotificationCenter defaultCenter] removeObserver;/有网络状态,3G或wifi
//
address;
if (networkStatus == NotReachable) { / :nil];
if (reachability) {
[reachability stopNotifier]1、注册通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityIsChanged:)
name;
[reachability startNotifier];
/
address;
reachability = [[Reachability reachabilityWithAddress;/无网络状态
//TODO
} else { :kReachabilityChangedNotification object:kReachabilityChangedNotification object.sin_family = AF_INET;
address.sin_port = htonl(IP_PORT);
address.sin_addr, sizeof(address));TODO
}
}
4:address] retain].sin_len = sizeof(address):self name.s_addr = htons(inet_addr(IP_Address));/开启网络检测
3、网络状态改变接受通知处理
-(void)reachabilityIsChanged;/关闭网络检测
[reachability release]:nil];
2、创建Reachability实例对象并开启通知
struct sockaddr_in address;
memset(address, 0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询