我应该在哪里执行可达性检查?

编程入门 行业动态 更新时间:2024-10-18 18:14:29
本文介绍了我应该在哪里执行可达性检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想检查有效的网络连接。我按照Apple的Reachability示例,并将我的支票放在 applicationDidFinishLaunching

#pragma mark - #pragma mark应用程序生命周期 - (BOOL)应用程序:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if(getenv NSZombieEnabled)|| getenv(NSAutoreleaseFreedObjectCheckEnabled)) { NSLog(@NSZombieEnabled / NSAutoreleaseFreedObjectCheckEnabled enabled! } //在应用程序启动后覆盖自定义点。 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged :) name:kReachabilityChangedNotification object:nil]; //检查连接 internetReach = [[Reachability reachabilityForInternetConnection] retain]; [internetReach startNotifer]; [self updateInterfaceWithReachability:internetReach]; [window addSubview:navigationController.view]; [window makeKeyAndVisible]; return YES;然而,我的应用程序会崩溃有时与错误 }

<应用程序无法及时启动

我已经将我的崩溃发送为SO问题: stackoverflow/questions/3908882/application-failed-to-launch-in-time

解决方案 / div>

在 -applicationDidBecomeActive 中,您可以在后台调用使用的可达性代码的方法 performSelectorInBackground:withObject:。

I want to check for a valid network connection. I followed Apple's Reachability example and put my check in applicationDidFinishLaunching

#pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled")) { NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!"); } // Override point for customization after application launch. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil]; //Check for connectivity internetReach = [[Reachability reachabilityForInternetConnection] retain]; [internetReach startNotifer]; [self updateInterfaceWithReachability: internetReach]; [window addSubview:navigationController.view]; [window makeKeyAndVisible]; return YES; }

However, my app will crash sometimes with the error Application Failed to Launch in Time

I have posted my crash as an SO question here: stackoverflow/questions/3908882/application-failed-to-launch-in-time

I'm not sure where I should perform the reachability check?

解决方案

In -applicationDidBecomeActive you may call a method in the background that uses the reachability code with -performSelectorInBackground:withObject:.

更多推荐

我应该在哪里执行可达性检查?

本文发布于:2023-11-14 00:22:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可达性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!