iOSiPhone可达性 – 如何仅使用Reachability.m.h来检查互联网是否丢失无法访问

iOSiPhone可达性 – 如何仅使用Reachability.m.h来检查互联网是否丢失无法访问,第1张

概述目前,我正在使用苹果可达性/ / .h的类,它可以工作,除了它通知我任何更改,其中,我想只通知用户,如果网络不可达.目前,如果我有一个互联网连接,然后松开网络告诉我.但是当您重新连接到网络时,它也会告诉我,我不想要.我想让它只有当有丢失/没有网络时才告诉我. 我相信这跟电话有关: - (void)viewWillAppear:(BOOL)animated{ // check for in 目前,我正在使用苹果可达性/ / .h的类,它可以工作,除了它通知我任何更改,其中,我想只通知用户,如果网络不可达.目前,如果我有一个互联网连接,然后松开网络告诉我.但是当您重新连接到网络时,它也会告诉我,我不想要.我想让它只有当有丢失/没有网络时才告诉我.

我相信这跟电话有关:@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来检查互联网是否丢失/无法访问所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1097411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存