我相信这跟电话有关:@H_419_3@
- (voID)vIEwWillAppear:(BOol)animated{ // check for internet connection [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangednotification object:nil]; internetReachable = [[Reachability reachabilityForInternetConnection] retain]; [internetReachable startNotifIEr]; // check if a pathway to a random host exists hostReachable = [[Reachability reachabilityWithHostname: @"www.Google.ca"] retain]; [hostReachable startNotifIEr]; // Now patIEntly wait for the notification}
当调用 – [NSNotificationCenter addobserver:selector:name:object:]时,名称是否具有任何其他功能,然后是字面上的名称?这是我第一次使用NSNotificationCenter,所以我不太懂这件事情.@H_419_3@
编辑:@H_419_3@
这是我的checkNetworkStatus功能:(问题是我正在收到“NotReachable”,因为网络连接回来,NSAlert多次关闭)@H_419_3@
- (voID) checkNetworkStatus:(NSNotification *)notice{ // called after network status changesNetworkStatus internetStatus = [internetReachable currentReachabilityStatus];switch (internetStatus){ case NotReachable: { UIAlertVIEw * alert = [[UIAlertVIEw alloc] initWithTitle:@"Network Failed" message:@"Please check your connection and try again." delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil ]; [alert show]; NSLog(@"The internet is down."); break; } case ReachableViaWiFi: { NSLog(@"The internet is working via WIFI."); break; } case ReachableViaWWAN: { NSLog(@"The internet is working via WWAN."); break; }}NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];switch (hostStatus){ case NotReachable: { NSLog(@"A gateway to the host server is down."); break; } case ReachableViaWiFi: { NSLog(@"A gateway to the host server is working via WIFI."); break; } case ReachableViaWWAN: { NSLog(@"A gateway to the host server is working via WWAN."); break; }}
}@H_419_3@解决方法 当状态发生变化时,可达到的通知将会发送通知,但是该通知的 *** 作完全取决于您.如果您不想告诉用户网络已经回来,您就不需要.
NSNotificationCenter方法中的“name”参数指示您订阅的通知.当一个对象发布通知时,它以特定的名称进行.@H_419_3@ 总结
以上是内存溢出为你收集整理的iOS / iPhone可达性 – 如何仅使用Reachability.m / .h来检查互联网是否丢失/无法访问全部内容,希望文章能够帮你解决iOS / iPhone可达性 – 如何仅使用Reachability.m / .h来检查互联网是否丢失/无法访问所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)