应用终止时,iOS Swift Handle通知单击

阿玛西的错

当我单击通知时,如何处理通知终止操作,当我单击通知时,我的应用只是将午餐的第一个屏幕作为正常的午餐,而不是我现在不希望的屏幕,或者我如何调试此问题以找出到底发生了什么

当应用程序运行或处于后台模式时,我通过以下方法处理通知点击操作:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                       didReceive response: UNNotificationResponse,
                                       withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID) tap")
        }
        NotificationCenter.default.post(name: .remoteNotificationActionName, object: nil, userInfo: userInfo)
        print("willPresent userInfo", userInfo)
        completionHandler()
    }

该通知将发送到场景委托类,并且从我的场景委托中,我将打开相应的屏幕:

@objc
private func remoteNotificationClickAction(notification: Notification){
    performRemoteNotificationClickAction(notification: notification)
}

private func performRemoteNotificationClickAction(notification: Notification){
    guard let userInfo = notification.userInfo else { return }
    guard let clickAction = NotificationsActions(rawValue: userInfo["click_action"] as? String ?? "") else { return }
    switch clickAction {
    case .dashboardAds:
        routeToNotifications()
    case .dashboardAdsContent:
        routeToNotifications()
    case .providerAcceptOrder, .providerOnWay, .providerArrive, .tripStarted, .addReceiverToChat:
        guard let orderString = userInfo["order"] as? String else { return }
        routeToActiveOrder(orderString: orderString)
    case .orderComplete:
        guard let orderString = userInfo["order"] as? String else { return }
        routeToServiceReport(orderString: orderString)
    case .orderCanceled, .receiverTracking, .receiverCancelOrder, .transportationDocumentIssued, .adminCancelOrder, .userCancelOrder:
        guard let orderString = userInfo["order"] as? String else { return }
        self.routeToOrderDetails(orderString: orderString)
    case .providerCancelOrderAccepted, .offerAdded, .receiverTrackingAccept, .orderExpired, .receiverTrackingReject, .offerWithdrawn:
        guard let orderString = userInfo["order"] as? String else { return }
        routeToSearchForServiceProvider(orderString: orderString)
    case .messageReceive:
        guard let orderString = userInfo["order"] as? String else { return }
        routeToChat(orderString: orderString)
    case .amountSent, .amountReceive, .amountAdded, .amountSubtracted, .withdrawAccepted, .withdrawRejected, .bankTransferAccepted, .bankTransferRejected:
        routeToWallet()
    case .pointsAdded:
        routeToTopUpPoints()
    case .reportClosed:
        routeToComplaints()
    default:  break
    }
    
}
阿玛西的错
 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = scene as? UIWindowScene else { return }
    window = UIWindow(windowScene: windowScene)
    whereToGo(window!)
    if let notificationResponse = connectionOptions.notificationResponse{
        NotificationCenter.default.post(name: .remoteNotificationActionName, object: nil, userInfo: notificationResponse.notification.request.content.userInfo)
    }
}

如上面的代码所示,我在connectionOptions.notificationResponse中收到的通知

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

通知单击时如何打开“活动”

来自分类Dev

如何处理IOS中的多个远程通知单击

来自分类Dev

如何在通知单击时正确打开文件

来自分类Dev

前台服务在通知单击时被杀死

来自分类Dev

在通知单击时打开已安装的PWA

来自分类Dev

如何在多个通知单击时显示适当的消息

来自分类Dev

应用未运行时,ios推送通知单击处理程序

来自分类Dev

使用ionic中的OneSignal插件在通知单击时路由到应用程序中的状态

来自分类Dev

UWP C#-从通知单击重新启动应用程序

来自分类Dev

通知单击后从后台打开应用程序后运行功能

来自分类Dev

ios 10通知单击不执行任何操作

来自分类Dev

使用 Ionic 2 在通知单击时导航到另一个屏幕

来自分类Dev

在通知单击时恢复辅助活动,计时器仍在运行

来自分类Dev

android-通知单击显示当前活动,如果应用程序已关闭则开始新活动

来自分类Dev

android-通知单击显示当前活动,如果应用程序已关闭则开始新活动

来自分类Dev

应用终止时处理推送通知

来自分类Dev

在应用终止时安排本地通知

来自分类Dev

iOS Swift-推送通知:将所有远程通知保存在数据库中(同时终止应用程序)

来自分类Dev

当应用程序通过推送通知从终止状态打开时,iOS Web 视图应用程序崩溃

来自分类Dev

当用户使用iOS Swift点击推送通知时,以特定视图打开应用

来自分类Dev

iOS(Swift) 收到推送通知时如何调用我的应用程序?

来自分类Dev

当应用程序从后台收到推送通知或在iOS中终止时,无法收听来自NSNotificationCenter的通知

来自分类Dev

应用未运行/应用终止时如何获取推送通知

来自分类Dev

当应用程序处于非活动状态并运行代码时,Swift iOS应用程序会收到推送通知

来自分类Dev

通知单击 NewIntent 未调用

来自分类Dev

在iOS中单击本地通知时不要打开应用

来自分类Dev

如何确保在应用终止后*释放iOS本地通知

来自分类Dev

如何确保在应用终止后*释放iOS本地通知

来自分类Dev

App终止iOS时不显示FCM通知

Related 相关文章

  1. 1

    通知单击时如何打开“活动”

  2. 2

    如何处理IOS中的多个远程通知单击

  3. 3

    如何在通知单击时正确打开文件

  4. 4

    前台服务在通知单击时被杀死

  5. 5

    在通知单击时打开已安装的PWA

  6. 6

    如何在多个通知单击时显示适当的消息

  7. 7

    应用未运行时,ios推送通知单击处理程序

  8. 8

    使用ionic中的OneSignal插件在通知单击时路由到应用程序中的状态

  9. 9

    UWP C#-从通知单击重新启动应用程序

  10. 10

    通知单击后从后台打开应用程序后运行功能

  11. 11

    ios 10通知单击不执行任何操作

  12. 12

    使用 Ionic 2 在通知单击时导航到另一个屏幕

  13. 13

    在通知单击时恢复辅助活动,计时器仍在运行

  14. 14

    android-通知单击显示当前活动,如果应用程序已关闭则开始新活动

  15. 15

    android-通知单击显示当前活动,如果应用程序已关闭则开始新活动

  16. 16

    应用终止时处理推送通知

  17. 17

    在应用终止时安排本地通知

  18. 18

    iOS Swift-推送通知:将所有远程通知保存在数据库中(同时终止应用程序)

  19. 19

    当应用程序通过推送通知从终止状态打开时,iOS Web 视图应用程序崩溃

  20. 20

    当用户使用iOS Swift点击推送通知时,以特定视图打开应用

  21. 21

    iOS(Swift) 收到推送通知时如何调用我的应用程序?

  22. 22

    当应用程序从后台收到推送通知或在iOS中终止时,无法收听来自NSNotificationCenter的通知

  23. 23

    应用未运行/应用终止时如何获取推送通知

  24. 24

    当应用程序处于非活动状态并运行代码时,Swift iOS应用程序会收到推送通知

  25. 25

    通知单击 NewIntent 未调用

  26. 26

    在iOS中单击本地通知时不要打开应用

  27. 27

    如何确保在应用终止后*释放iOS本地通知

  28. 28

    如何确保在应用终止后*释放iOS本地通知

  29. 29

    App终止iOS时不显示FCM通知

热门标签

归档