首页 > 解决方案 > 使用 Flutter App 在 iOS 中未触发 UNUserNotificationCenterDelegate didReceive

问题描述

我在flutter App中使用APNS for iOS(使用Swift)设置了推送通知。当应用程序收到来自 AWS Pinpoint 的推送通知时,会触发 didReceiveRemoteNotification。但是当用户点击通知时,没有其他方法被触发。一旦我处理了推送通知上的用户操作,我就可以使用 openUrl 调用一个方案到应用程序上的特定路由。

我尝试在 Xcode 的功能中禁用/启用后台模式。还验证了功能中是否打开了推送通知。Pinpoint 使用 APNS 将通知发送到 iOS 并使用 Firebase 将通知发送到 Android,这工作正常。

还尝试将 iOS 目标版本设置为 10.0、11.0 和 12.0

UNUserNotificationCenter.current().delegate = self 在 didFinishLaunchingWithOptions 中声明并导入 UserNotifications

当我点击推送通知时,这将打印在控制台中:

警告:UNUserNotificationCenter 委托收到了对 -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: 的调用,但从未调用过完成处理程序。

来自精确的有效载荷:

[AnyHashable("aps"): {
    alert =     {
        body = "BODY";
        title = "TITLE";
    };
    badge = 0;
    "content-available" = 1;
    "mutable-content" = 0;
    sound = default;
}]

代码,

extension AppDelegate: UNUserNotificationCenterDelegate {
        func userNotificationCenter(_ center: UNUserNotificationCenter,
                                    willPresent notification: UNNotification,
                                    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

            let userInfo = notification.request.content.userInfo

            // Print full message.
            print(userInfo)

            // Change this to your preferred presentation option
            completionHandler([])
        }

        func userNotificationCenter(_ center: UNUserNotificationCenter,
                                    didReceive response: UNNotificationResponse,
                                    withCompletionHandler completionHandler: @escaping () -> Void) {
            let userInfo = response.notification.request.content.userInfo

            // Print full message.
            print(userInfo)

            completionHandler()
        }

    }

当用户点击在我的情况下没有发生的推送通知时,预计会触发 didReceive。

任何人都可以帮助我了解如何在用户点击推送通知时触发?

标签: iosxcodeflutterapple-push-notificationsaws-pinpoint

解决方案


我面临着类似的问题。iOS swift 委托方法没有被触发。看来这些方法必须已被声明为公共的。

只需更换

func userNotificationCenter

public func userNotificationCenter

也许它会帮助某人......


推荐阅读