【问题标题】:UNUserNotificationCenterDelegate didReceive is not getting triggered in iOS with Flutter App使用 Flutter App 在 iOS 中未触发 UNUserNotificationCenterDelegate didReceive
【发布时间】:2019-06-26 19:05:08
【问题描述】:

我在 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 预计会在用户点击推送通知时触发,这在我的情况下没有发生。

谁能帮我了解当用户点击推送通知时如何触发?

【问题讨论】:

  • 尝试将“mutable-content”设置为“1”。
  • 那行不通。我想这主要用于根据此处的文档修改通知内容。 developer.apple.com/library/archive/documentation/…
  • 我昨天尝试的一个是“相同的代码正在使用 Swift 的 Native iOS App 工作”当相同的代码通过 Flutter 应用程序运行时,它不起作用。主要区别在于 FlutterAppDelegate

标签: ios xcode flutter apple-push-notifications aws-pinpoint


【解决方案1】:

我遇到了类似的问题。 iOS swift 委托方法没有被触发。看来这些方法一定是公开的。

只需替换

func userNotificationCenter

public func userNotificationCenter

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

【讨论】:

    【解决方案2】:

    你设置了中心的委托属性吗?

    center.delegate = self
    

    其中selfAppDelegate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 2017-03-02
      • 2021-09-08
      • 2019-01-14
      • 2020-07-05
      相关资源
      最近更新 更多