Search code examples
iosobjective-cxctestuitest

"Unable to monitor event loop" crash


I add breakpoint and find that it block in the method that

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// init local data
    [[PDKeychainBindings sharedKeychainBindings] setObject:@"0" forKey:kNEED_GESTURE_LOGIN];

    // register notification to notice switching RootVC
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(switchRootControllerWithType:)
                                                 name:kNoti_SwitchRootView
                                               object:nil];

    // init the third part SDK
    [self setupShareSDK];
    [self setupBugly];
    [self setupUMeng];
    [self setupIQKeyBoard];
    [self setupZhugeIOWithOptions:launchOptions];
    [self setupTrusfort];   
    // register push service
    [self setupJPushWithOptions:launchOptions];
    [self dealWithRemoteNotification:launchOptions];

    // set local flag
    [KXUserIntroManager setupFlag];

    if (self.remoteNotification) {
        if ([AccountStateManager isLogin])
            [self.loginNavigationController showGesturePDViewController];
        self.window.rootViewController = self.loginNavigationController;

    } else { 
        self.window.rootViewController = self.launchController;
    }
    return YES;
}

i also try the way in stackOverFlow ,Add the following code to the above method

    NSArray *args = [NSProcessInfo processInfo].arguments;
    for(NSString *arg in args){
        if ([arg isEqualToString:@"NoAnimations"]) {
            [UIView setAnimationsEnabled:false];
        }
    }

Image link

it is the detail of didFinishLaunching method. it just init some data and create a notification


Solution

  • While this is not a direct answer to your question, it may well be that your issue is symptomatic of the very evident fact that you are doing much too much work, on the main thread, in didFinishLaunchingWithOptions. Your main job in this method is to get out of the way and let the runtime launch the app. You are doing the exact opposite of that.