【发布时间】:2016-02-11 17:34:10
【问题描述】:
我正在开发一个持续跟踪互联网连接并上传一些数据的应用程序,该应用程序具有以下功能:当互联网不可用时,它会离线保存数据(照片),而在互联网可用时它会上传数据。我的应用程序运行良好,但有时它不能检查互联网,当我关闭设备 wifi 并再次打开时,它正在工作,所以有人可以告诉我这里有什么问题让我卡住了吗?我的可达性代码如下:
代码
- (void)reachabilityCheck
{
/* Internet checking */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
reach.reachableOnWWAN = YES;
[reach startNotifier];
NetworkStatus internetStatus = [reach currentReachabilityStatus];
if (internetStatus != NotReachable) {
//Develop By Payal
if(self.internetConnection == 0)
{
NSLog(@"Connection active");
self.internetConnection = 1;
}
//Develop By Payal Done
}
else {
NSLog(@"Connection inactive");
self.internetConnection = 0;
}
}
【问题讨论】:
标签: ios objective-c iphone reachability