【发布时间】: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