我应该在哪里执行可达性检查? [英] Where should I perform a Reachability check?

查看:69
本文介绍了我应该在哪里执行可达性检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查有效的网络连接。我按照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问题: http://stackoverflow.com/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: http://stackoverflow.com/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:.

这篇关于我应该在哪里执行可达性检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆