gpt4 book ai didi

ios - 限制在 iPad 应用程序中检查互联网连接的时间

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

我有一个应用程序使用以下内容检查是否有互联网连接。有什么方法可以限制检查所需的时间吗?如果无线连接信号较弱,则应用程序可能需要一段时间才能进行检查。

- (BOOL)connectedToInternet
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"http://www.google.com/"]];
[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL];
return ([response statusCode] == 200) ? YES : NO;
}

最佳答案

只需设置超时时间:

[request setTimeoutInterval:10];

以上将超时设置为 10 秒,您可以根据需要调整该数字。

关于ios - 限制在 iPad 应用程序中检查互联网连接的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320131/

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