gpt4 book ai didi

ios - 等待进入 Controller ,直到 wifi 启用 IOS

转载 作者:行者123 更新时间:2023-11-28 20:11:21 27 4
gpt4 key购买 nike

我的应用程序中有一个 Controller 需要互联网连接才能运行。我知道如果设备在应用程序开始之前有或没有互联网连接我必须做什么。尽管我一直坚持用户必须启用互联网连接到应用程序的问题。我有一种方法可以检查是否有互联网连接,如果没有,它会显示警报 View 。我想保留到这个 View Controller ,直到启用互联网。这是我的功能代码不起作用。欢迎任何建议。

- (void) checkIfInternetEnabled{

Reachability *hostReach = [Reachability reachabilityWithHostName: @"www.apple.com"] ;

NetworkStatus netStatus = [hostReach currentReachabilityStatus];

if (netStatus != ReachableViaWiFi){

NSLog(@"oooaoaoaolaoeworolaowoeoal");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You must enable wi-fi the first time that you use the application for complete installation " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alert show];

netStatus = [hostReach currentReachabilityStatus];

while(netStatus!= ReachableViaWiFi){

[alert show];

netStatus = [hostReach currentReachabilityStatus];

}

}

}

最佳答案

您应该收听 reachability 类发送的有关网络状态更改的通知(您应该使用 reachability 2.x):

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];

关于ios - 等待进入 Controller ,直到 wifi 启用 IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20066724/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com