我想检查有效的网络连接。我按照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:.
更多推荐
我应该在哪里执行可达性检查?
发布评论