点击“从推送通知中清除”时,突然重定向到深层链接

When tap Clear from push notification suddenly redirect to deeplink

提问人:ferryawijayanto 提问时间:12/14/2022 更新时间:12/17/2022 访问量:156

问:

当我收到通知时,我有一个来自后端的深层链接。这种情况是每当我尝试清除通知中心时,例如滑动清除,清除按钮重定向到我的深层链接。轻扫清除时的行为应从通知中心删除通知。但就我而言,事实并非如此。

它发生在选定的设备中,而在我的设备中没有发生,我尝试解决此stackoverflow问题清除通知中的清除按钮

但是我尝试了这种方法,仍然不起作用。

我在appDelegate中设置了我的UNNotificationCenter

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  completionHandler([.alert, .badge, .sound])
  let userInfo = notification.request.content.userInfo
  appScreenViewModel.handlePushNotificationInApp(userInfo: userInfo)
  guard  let aps = userInfo["aps"] as? [String: Any], let category = aps["category"] as? String else { return }
  let clearAction = UNNotificationAction(identifier: UNNotificationDismissActionIdentifier, title: "Clear", options: [])
  UNNotificationCategory(identifier: category, actions: [clearAction], intentIdentifiers: [], options: .customDismissAction)
}

这是我在userNotification didReceived响应中处理通知

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    MoEngage.sharedInstance().userNotificationCenter(center, didReceive: response)
    let userInfo = response.notification.request.content.userInfo
    appScreenViewModel.handlePushNotification(userInfo: userInfo)
    if response.actionIdentifier == UNNotificationDismissActionIdentifier {
    UNUserNotificationCenter.current().removeAllDeliveredNotifications()
  }
}

这是我收到的有效载荷

"aps": {
    "alert": {
      "title": "Notification Title",
      "subtitle": "Notification Subtitle",
      "body": "Notification Body"
    },
    "badge": 1,
    "sound": "default",
    "category": "INVITE_CATEGORY",
    "content-available": 1,
    "mutable-content": 1
  }

我哪里做错了?

iOS Swift 推送通知 通知中心

评论


答:

0赞 ferryawijayanto 12/17/2022 #1

对不起,我已经找到了解决方案,如果您不想在点击清除时重定向到深度链接。我所做的是这样的

if response.actionIdentifier != UNNotificationDismissActionIdentifier {
    appScreenViewModel.handlePushNotification(userInfo: userInfo)
}