didReceiveRemoteNotification 时更改视图
Posted
技术标签:
【中文标题】didReceiveRemoteNotification 时更改视图【英文标题】:Change view when didReceiveRemoteNotification 【发布时间】:2013-06-07 16:23:01 【问题描述】:当我收到远程通知时,我试图从 App 委托方法更改为主视图,以便在主视图中执行转场到另一个视图,但我收到 NSInvalidArgumentException
didReceiveRemoteNotification 时 App Delegate 中的代码:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
EmergencyMasterViewController* maincontroller = (EmergencyMasterViewController*)self.window.rootViewController;
[maincontroller alert];
MasterView 中的代码:
-(void)alert
[self performSegueWithIdentifier: @"Warning" sender: self];
我得到的错误是:[UINavigationController alert]: unrecognized selector
【问题讨论】:
【参考方案1】:这是因为你的窗口 rootViewController 实际上是一个 UINavigationController 而不是你的 EmergencyMasterViewController。您需要检查如何在应用委托 didFinishLaunchingWithOptions 或类似内容中分配窗口根视图控制器。
尝试将视图控制器嵌入到导航控制器中,例如:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
NSArray *viewControllers = navigationController.viewControllers
EmergencyMasterViewController *maincontroller = [viewControllers objectAtIndex:0];
在您尝试获取 EmergencyMasterViewController 之前,UINavigationController 先弹出到根视图控制器可能更安全,以防用户已经在导航堆栈中导航:
[navigationController popToRootViewControllerAnimated:NO];
【讨论】:
以上是关于didReceiveRemoteNotification 时更改视图的主要内容,如果未能解决你的问题,请参考以下文章
尽管 content_available = true,但没有在后台调用 didReceiveRemoteNotification