gpt4 book ai didi

iphone - 检查 iphone 进程之间的 Internet 连接

转载 作者:行者123 更新时间:2023-12-01 17:32:40 25 4
gpt4 key购买 nike

我有以下代码

NSURL *url = [NSURL URLWithString:@"http://wallpaperswide.com/download/flattened_grass-wallpaper-2800x1050.jpg"];  //Line1
NSData *data = [[NSData alloc] initWithContentsOfURL:url]; //Line2
UIImage *tmpImage = [[UIImage alloc] initWithData:data]; //Line3
NSLog(@"%@",tmpImage); //Line4

在第 2 行中,下载该 url 中的图像需要一些时间……在这之间我必须检查互联网连接……这怎么可能?

我会详细解释我的问题....

upto line1 我的 iphone 有互联网连接。现在 line2 正在执行......在下载过程中,在这个过程的中间,我失去了我的互联网连接......

现在我如何通知用户“您没有互联网连接”...

那么如何检查此过程之间的 Internet 连接。?

是否有任何委托(delegate)方法...请帮助我

提前致谢.....

最佳答案

你可以做这样的事情

Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus == NotReachable) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Could not connect to the server, please check your internet connection !" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];


}
else
{

}

}

关于iphone - 检查 iphone 进程之间的 Internet 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062310/

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