我正在尝试将myViewController
myVC
的对象设置为AppDelegate
上的窗口的rootViewController,如下所示:
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
self.myVC=(myViewController*)self.window.rootViewController;
}
当应用程序运行时,这一切都正常工作,但在后台它根本不起作用。
有人知道我怎样才能让它在后台运作?
谢谢!
答案 0 :(得分:0)
试试这个
修改强>
<强> AppDelegate.m 强>
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
ViewController *ViewController = [storyboard instantiateViewControllerWithIdentifier:@"YOUR_IDENTIFIER"];[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:ViewController animated:YES completion:NULL];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"applicationDidEnterBackground");
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:ADD_YOURCONTROLLER];
[self presentViewController:navController animated:YES completion:nil];
}
希望这有帮助。