【发布时间】:2020-10-31 20:42:02
【问题描述】:
我正在尝试使用 CLI 功能向 Android 和 iOS 设备发送推送通知。当我使用 iOS 版本时,从我的函数发送时没有收到通知。但是,当我从 Firebase 控制台发送它们时,它只会在应用程序打开时收到通知。我在想我错过了设置中的一个或多个关键步骤,或者我的函数在有效负载中没有所有需要的数据。
我的函数发送如下:
return Promise.all([token]).then(result=>{
const payload = {
notification: {
title : likename + " liked your post!",
"priority" : "high"
}
};
console.log(token);
return admin.messaging().sendToDevice(token,payload);
});
我的 iOS 应用程序设置了证书,并按如下方式实现了我的 APP 委托:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
非常感谢任何帮助,如果您需要更多信息,请告诉我。
【问题讨论】:
标签: ios flutter push-notification google-cloud-functions apple-push-notifications