我更改了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)
答案 0 :(得分:0)
在处理本地通知之前将此代码放入
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];