ios 如何在推送通知中启动应用程序

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

当用户将在 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/

相关文章:

ios - boundingRectWithSize :options:attributes:context: is not returning accurate expected UILabel size

ios - 在构建时在 Xcode 4 中动态设置 iOS bundle 显示名称

ios - 在 CoreGraphics 中使用图像描边 CGContext 路径

ios - 没有 IBInspectables 的 IBDesignable UIButton IB 渲染

ios - 如何通过 Storyboard 将数据从推送通知传递到 ViewController?

ios - 为什么数据多次添加到数组中?

ios - 无法获取 Facebook Graph API 用户照片边缘的单个大尺寸

ios - 尝试使用 Swift3 将图像上传到 CloudKit 时出错

ios - RegisterUserNotificationSettings 干扰网络请求

ios - Apple 推送通知不再到达