我的故事板中有一个视图层次结构
RootController(UIViewController)
|
|
MainNavigationController(UINavigationController)
| | | |
| | | |
LoginController SignInController MainPageController DetailControl
如果用户已登录" MainPageController"如果不是那么被推动" SigInController"被推入导航堆栈。来自" MainPageController"," DetailControl"将根据用户选择推送。
现在这是我在推送通知时尝试做的事情。应用程序在后台和" MainPageController"在导航堆栈的顶部。通知点击应推送" DetailControl"为实现这一点,我将此作为我的代码
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateActive) {
NSLog(@"Application Active");
} else if(application.applicationState == UIApplicationStateBackground){
NSLog(@"Application Background");
} else if(application.applicationState == UIApplicationStateInactive){
[self handleNotificationWithEntity:[[userInfo objectForKey:@"aps"] objectForKey:@"entity"] withEntityId:[[userInfo objectForKey:@"aps"] objectForKey:@"entityid"]];
}
}
-(void) handleNotificationWithEntity:(NSString *) entity withEntityId:(NSString *) entityid
{
RootController *rootController = (RootController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
MainNavigationController *mvc = (MainNavigationController *)[rootController rootNavController];
[mvc popToRootViewControllerAnimated:true];
NSLog(@"%@",mvc.topViewController);
// code to push detail controller here [mvc pushviewcontroller]
}
" Detailviewcontroller"没有被推入堆栈并且也排队" NSLog(@"%@",mvc.topViewController);"打印" LoginController"而我期待" MainPageController"应该打印出来
谢谢