调用addMessageFromRemoteNotification应用程序崩溃时:
//Appdelegate.m: these methods assist in showing a speech bubble with a text payload when a message is sent
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
- (void)addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI{
UINavigationController *navigationController =
(UINavigationController*)_window.rootViewController;
ChatViewController *chatViewController = (ChatViewController*). [navigationController.viewControllers objectAtIndex:0];
DataModel *dataModel = chatViewController.dataModel;
//
...
}
为了用户体验,初始视图已从NavigationControllerconnected to更改ChatViewController为NavigationControllerconnected to ViewController。
可以ChatViewController和它使用的仍然以编程方式在这些语句中使用,以便在运行时加载视图时调用 addMessageFromRemoteNotification 时NavigationControlelr仍然可以更新?UI
更改 Storyboard 中的初始视图后,rootViewController 类属性显式设置新的初始视图:ViewController 作为方法中的 rootViewController,并且当稍后在屏幕演示中addMessageFromRemoteNotification调用该方法时应用程序崩溃。ChatViewController
调试器窗口
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[ViewController didSaveMessage:atIndex:]: unrecognized selector sent to instance 0x15d544e0'
UI当应用程序关闭时在 iPad 上收到通知,但在使用时运行时不更新instantiateViewControllerWithIdentifier。
ChatViewController* chatViewController = (ChatViewController*)
[ApplicationDelegate.storyBoard instantiateViewControllerWithIdentifier:@"ChatViewController"];
DataModel *dataModel = chatViewController.dataModel;