【问题标题】:ios How to launch application in push notificationios 如何在推送通知中启动应用程序
【发布时间】:2017-11-08 08:07:01
【问题描述】:

当用户在 ios 中收到推送通知时,我在启动特定应用程序页面时遇到问题。

这可能吗?

如果是,请您帮我解决一下。

【问题讨论】:

标签: ios swift push-notification apple-push-notifications


【解决方案1】:

您可以在收到任何远程通知时向自己发送通知,并通过在此通知中注册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];

}

如果您遇到任何问题,请告诉我。

【讨论】:

  • 检查。感谢您的快速帮助。
猜你喜欢
  • 2013-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多