xcode 应用程序未能及时启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3908882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:49:42  来源:igfitidea点击:

Application Failed to Launch in Time

iphoneobjective-cxcodedebuggingios4

提问by Sheehan Alam

How can I diagnose this error?

如何诊断此错误?

Application Specific Information:
    MyApp failed to launch in time

    Elapsed total CPU time (seconds): 4913.443 (user 3868.270, system 1045.173), 56% CPU 
    Elapsed application CPU time (seconds): 0.010, 0% CPU

    Backtrace not available

    Unknown thread crashed with unknown flavor: 5, state_count: 1

    Binary Images:
    0x2fe00000 - 0x2fe26fff  dyld armv7  <a11905c8ef7906bf4b8910fc551f9dbb> /usr/lib/dyld

Here is my didFinishLaunchingmethod:

这是我的didFinishLaunching方法:

#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;
    }

回答by Philippe Leybaert

You're probably doing a lot of setup work in your AppDelegate's application:didFinishLaunchingmethod.

您可能在 AppDelegate 的application:didFinishLaunching方法中做了很多设置工作。

You should make sure this function exits as soon as possible. Any setup-work that takes time (network access for example) should be done asynchronously in your application. While this is going on, you can show a spinner to indicate to the user that the application is loading.

您应该确保该函数尽快退出。任何需要时间的设置工作(例如网络访问)都应该在您的应用程序中异步完成。在此过程中,您可以显示一个微调器以向用户表明应用程序正在加载。

回答by Martin Magakian

In order to add so information to Philippe Leybaert response.
If the application take to much time to start the main thread will be kill so the application will crash.

为了将此类信息添加到 Philippe Leybaert 的回复中。
如果应用程序需要很长时间来启动主线程将被杀死,因此应用程序将崩溃。

  • When you're using the simulator, it will not crash.
  • When you are using your iphone connected to xcode it will not crash.
  • When you send it for App Store it might be acceptedif the Apple tester is using a fast iPhone
  • When your users on slow like iPhone 3S will crash
  • 当您使用模拟器时,它不会崩溃
  • 当您使用连接到 xcode 的 iphone 时,它不会崩溃
  • 当您将它发送到 App Store 时,如果 Apple 测试人员使用的是快速 iPhone,它可能会被接受
  • 当你的用户像 iPhone 3S 这样运行缓慢时会崩溃

A way to test this issu before submitting is to deploy to testflight or with adhocand install it on the slower device you want to support.

在提交之前测试此问题的一种方法是部署到testflight 或使用 adhoc并将其安装在您想要支持的较慢的设备上。

回答by Ankit Vyas

Just try to divide your application:didFinishLaunchingWithOptions: method code to different function calls and make those calls in background using the threads other then main and make sure that application:didFinishLaunchingWithOptions: method returns as soon as possible

只需尝试将您的应用程序:didFinishLaunchingWithOptions:方法代码划分为不同的函数调用,并使用除主线程之外的线程在后台进行这些调用,并确保应用程序:didFinishLaunchingWithOptions:方法尽快返回

you can use

您可以使用

dispatch_async(dispatch_get_main_queue(), ^{
//put your code
}

I have resolved the issue using this code !

我已经使用此代码解决了问题!