iOS - 收到推送通知后阅读
iOS - Read the push notification once Received
我有4个场景
应用未启动时
鉴于应用程序未启动或终止
当推送通知收到
并在不点击通知的情况下打开应用程序
然后应用程序应该捕获通知。
当应用 运行 在前台时
给定应用 运行 在前台
当推送通知收到
然后应用程序应该捕获通知。
当应用 运行 在后台时
鉴于该应用 运行 在后台运行
当推送通知收到
并在不点击通知的情况下打开应用程序
然后应用程序应该捕获通知。
当应用未启动并清除通知时
鉴于应用程序未启动或终止
当推送通知收到
并且用户清除了通知
并打开应用程序
然后应用程序应该捕获通知。
前 3 个场景适用于以下代码
最后一个场景不工作当应用程序未启动并清除通知时
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { requests in
for request in requests {
self.setNotification(userInfo: request.request.content.userInfo as NSDictionary)
}
})
}
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
setNotification(userInfo: userInfo as NSDictionary)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
setNotification(userInfo: userInfo as NSDictionary)
}
根据您的查询
When the app is not Launched and cleared the notification
Given the app is not Launched or Killed When the post notification
receive And user cleared the notification And opened the app Then the
app should capture the notification.
这对于普通推送通知是不可能的,除非用户与该通知进行交互。您可能想尝试 静默通知 ,这些未在 UI 中显示,但控件会到达应用程序,您可以在代码中使用 data/payload .
当用户清除栏中的通知时,无法获取该信息。
您还可以尝试在 API 中添加在推送中发送的相同信息,并在用户打开应用程序后调用它。
This link 处理所有涉及的细节。根据你的实现,你可以尝试两者的结合。
我有4个场景
应用未启动时
鉴于应用程序未启动或终止
当推送通知收到
并在不点击通知的情况下打开应用程序
然后应用程序应该捕获通知。
当应用 运行 在前台时
给定应用 运行 在前台
当推送通知收到
然后应用程序应该捕获通知。
当应用 运行 在后台时
鉴于该应用 运行 在后台运行
当推送通知收到
并在不点击通知的情况下打开应用程序
然后应用程序应该捕获通知。
当应用未启动并清除通知时
鉴于应用程序未启动或终止
当推送通知收到
并且用户清除了通知
并打开应用程序
然后应用程序应该捕获通知。
前 3 个场景适用于以下代码
最后一个场景不工作当应用程序未启动并清除通知时
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { requests in
for request in requests {
self.setNotification(userInfo: request.request.content.userInfo as NSDictionary)
}
})
}
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
setNotification(userInfo: userInfo as NSDictionary)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
setNotification(userInfo: userInfo as NSDictionary)
}
根据您的查询
When the app is not Launched and cleared the notification
Given the app is not Launched or Killed When the post notification receive And user cleared the notification And opened the app Then the app should capture the notification.
这对于普通推送通知是不可能的,除非用户与该通知进行交互。您可能想尝试 静默通知 ,这些未在 UI 中显示,但控件会到达应用程序,您可以在代码中使用 data/payload .
当用户清除栏中的通知时,无法获取该信息。 您还可以尝试在 API 中添加在推送中发送的相同信息,并在用户打开应用程序后调用它。
This link 处理所有涉及的细节。根据你的实现,你可以尝试两者的结合。