这是显示聊天对话的当前设置。
1):推送通知到达
2):didRecieveRemoteNotification:获取有效负载并执行 NSNotification 发布到根视图控制器(初始视图)这是 UITabBarController
3):UITabBarController接收NSNotification。观察并执行一个执行的函数([self setSelectedIndex:2];)并使用 NSNotification
发送相同的有效负载4):NavigationController使用Observer接收NSNotification Payload执行该功能,并对UINavigationController中嵌入的聊天对话Viewcontroller执行Push Segue
这个步骤适用于我,除了很长一段时间传递数据直到到达最终目的地,更不用说这会导致许多推送导致损坏 NavigationController 时出现问题。
我想要实现的是来自AppDelegate show Chat Conversation ViewController与它的 NavigationController 并且不会导致同样的损坏 navigationController 一遍又一遍地制作相同的显示器。同时从推送通知中传递PayLoad。
这是我的AppDelegate didRecieveRemoteNotification:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if([[userInfo objectForKey:@"viewController"] isEqual: @"chat_controller"]){
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
NSDictionary *userDictionary = @{@"nick_from" : [userInfo objectForKey:@"nick_from"],@"nick_to" : [userInfo objectForKey:@"nick_to"]};
[self pushChatNotification:userDictionary];
}
else {
NSString *message = [NSString stringWithFormat:@"%@ sent you a message want to reply?",[userInfo objectForKey:@"nick_from"]];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New message"
message:message
delegate:self
cancelButtonTitle:@"Reply"
otherButtonTitles:@"Cancel", nil];
[alertView show];
}
}
}
-(void)pushChatNotification:(NSDictionary *)userDictionary {
[[NSNotificationCenter defaultCenter] postNotificationName:@"conversationParameters"
object:nil
userInfo:userDictionary];
}