可达性块应用

发布于 2024-12-17 11:27:10 字数 722 浏览 5 评论 0原文

在我的应用程序中的 appDelegate .mi 中插入了像苹果所说的可达性代码:

-(BOOL)checkInternet
{
Reachability *r = [Reachability reachabilityWithHostName:@"google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
    internet = NO;
} else {
    internet = YES;
}
return internet;
}

并在我的 viewcontroller.m 中的方法中 - (void)applicationDidBecomeActive:(UIApplication *)application {

gotInternet = [self checkInternet];
if ( gotInternet == 0)
{
//No connection
} else {
//Connection ok
} 

但是当网络 3g 出现问题时我的应用程序之后大约 20 秒,由于延迟太大,它崩溃了。如何异步实现控制连接,而不带看门狗?

谢谢

in my app in the appDelegate .m i have insert the reachability code like apple say:

-(BOOL)checkInternet
{
Reachability *r = [Reachability reachabilityWithHostName:@"google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
    internet = NO;
} else {
    internet = YES;
}
return internet;
}

and in my viewcontroller.m in the method - (void)applicationDidBecomeActive:(UIApplication *)application {

gotInternet = [self checkInternet];
if ( gotInternet == 0)
{
//No connection
} else {
//Connection ok
} 

but when there are problems on the network 3g my application after about 20 seconds it crashes because of too much latency. How do I implement the control connection asynchronously, never to take the watchdog?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2024-12-24 11:27:10

看看 NSOperation并发编程指南

Have a look at NSOperation and the concurrency programming guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文