将本地通知脚本添加到" didFinishLaunchingWithOptions"时,无法加载ViewController。

时间:2014-07-17 19:43:18

标签: ios uilocalnotification

在" didFinishLaunchingWithOptions"中添加本地通知脚本后它说

  

[1627:60b]应用程序窗口应具有根视图   应用程序启动结束时的控制器

这是代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
mainStoryboard = nil;
if (IS_IPHONE_5) {
    mainStoryboard = [UIStoryboard storyboardWithName:@"MainIPhone5" bundle:nil];
}
else {
    mainStoryboard = [UIStoryboard storyboardWithName:@"MainIPhone" bundle:nil];
}
UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
    SelectedTask = [localNotification.userInfo objectForKey:@"FullTaskName"];
    TaskViewController *TaskViewControllerVar;
    TaskViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:@"TaskViewController"];
    TaskViewControllerVar.SelectedTask = SelectedTask;
    self.window.rootViewController = TaskViewControllerVar;
    NSLog(@"1");
}else{
    RecordingViewController *RecordingViewControllerVar;
    RecordingViewControllerVar = [mainStoryboard instantiateViewControllerWithIdentifier:@"RecordingViewController"];
    self.window.rootViewController = RecordingViewControllerVar;
    NSLog(@"2");
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
return YES;

}

1 个答案:

答案 0 :(得分:0)

删除此行

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

您还需要添加视图。像这样:

self.window.rootViewController = TaskViewControllerVar;
[self.window addSubview:TaskViewControllerVar.view];

self.window.rootViewController = RecordingViewControllerVar;
[self.window addSubview:RecordingViewControllerVar.view];