当用户将在 ios 中收到推送通知时,我在启动特定应用程序页面时遇到问题。
这可能吗?
如果是,你能帮我吗?
最佳答案
您可以在收到任何远程通知时向自己发送通知,并通过将 UIViewController
注册到此通知,您可以在收到通知后打开特定的 UIViewController
。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
}
在您的 FirstViewController.m 中注册以收听此通知。
-(void)viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];
}
在方法中你可以打开特定的viewController
-(void)pushNotificationReceived{
[self presentViewController:self.secondViewController animated:YES completion:nil];
}
最后在 dealloc 方法中取消注册当前 viewController 的通知
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
如果您遇到任何问题,请告诉我。
关于ios 如何在推送通知中启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47174494/