【发布时间】:2017-11-08 08:07:01
【问题描述】:
当用户在 ios 中收到推送通知时,我在启动特定应用程序页面时遇到问题。
这可能吗?
如果是,请您帮我解决一下。
【问题讨论】:
-
启动应用页面是指打开应用?详细...
标签: ios swift push-notification apple-push-notifications
当用户在 ios 中收到推送通知时,我在启动特定应用程序页面时遇到问题。
这可能吗?
如果是,请您帮我解决一下。
【问题讨论】:
标签: ios swift push-notification apple-push-notifications
您可以在收到任何远程通知时向自己发送通知,并通过在此通知中注册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];
}
如果您遇到任何问题,请告诉我。
【讨论】: