它没有加载任何屏幕并在didFinishLaunchingWithOptions中崩溃

时间:2014-07-21 02:23:11

标签: ios uilocalnotification

我更改了didFinishLaunchingWithOptions,使其在另一个ViewController中运行,如果它从UILocalNotification运行,但它只是加载任何内容,它的黑屏和应用程序崩溃。这是代码:

UIStoryboard *mainStoryboard;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    mainStoryboard = nil;        
    mainStoryboard = [UIStoryboard storyboardWithName:@"MainIPhone5" bundle:nil];

    UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];

    if (localNotification) {
        TaskViewController *TaskViewControllerVar;
        TaskViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:@"TaskViewController"];
        self.window.rootViewController = TaskViewControllerVar;
        [self.window addSubview:TaskViewControllerVar.view];
        NSLog(@"1");
    }else{
        RecordingViewController *RecordingViewControllerVar = [[RecordingViewController alloc] init];
        RecordingViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:@"RecordingViewController"];
        self.window.rootViewController = RecordingViewControllerVar;
        [self.window addSubview:RecordingViewControllerVar.view];
        NSLog(@"2");
    }

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    return YES;
}

这是错误

2014-07-21 05:13:14.946 TaskRecorder[1188:60b] 2

2014-07-21 05:13:14.951 TaskRecorder[1188:60b] Application windows are expected to have a root view controller at the end of application launch

2014-07-21 05:13:19.953 TaskRecorder[1188:60b] Warning: Attempt to present <ViewController: 0x109f0f8a0> on <RecordingViewController: 0x109d4f730> whose view is not in the window hierarchy!
(lldb)

1 个答案:

答案 0 :(得分:0)

在处理本地通知之前将此代码放入

  

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];