在通知横幅中显示之前处理推送通知
Handle Push Notification before it is displayed in the Notifications Banner
我想在收到远程通知时在应用程序中执行一些代码,然后再显示 IOS 通知的 Banner/Alert。我的想法是捕捉通知中的 json,并根据它的内容和其他规则,我知道是否应该为用户显示通知。
您可以创建 "silent" 推送通知。 (参见 Apple 文档)当您收到这样的静默通知时:
- 解析 JSON
- 决定是否显示
- 如果是,只显示一个普通的本地通知,它看起来和用户的推送通知一样
您会发现大量有关如何创建本地通知的 SO 教程。
您必须实施 application:didReceiveRemoteNotification:fetchCompletionHandler。
Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
我想在收到远程通知时在应用程序中执行一些代码,然后再显示 IOS 通知的 Banner/Alert。我的想法是捕捉通知中的 json,并根据它的内容和其他规则,我知道是否应该为用户显示通知。
您可以创建 "silent" 推送通知。 (参见 Apple 文档)当您收到这样的静默通知时:
- 解析 JSON
- 决定是否显示
- 如果是,只显示一个普通的本地通知,它看起来和用户的推送通知一样
您会发现大量有关如何创建本地通知的 SO 教程。
您必须实施 application:didReceiveRemoteNotification:fetchCompletionHandler。
Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.