【发布时间】:2021-11-27 18:39:17
【问题描述】:
我正在接收来自 firebase 的消息,以获取带有 APN 的通知。在 Firebase 中,我有 APNs 密钥的证书,在 Firebase 中的 Xcode 项目中具有相同的 ID,该 ID 是从 Apple Developer 中提取的。
但我不知道为什么会发生这种情况,我收到了这个错误,它在消息扩展中注册了两个令牌:
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {}}
在检索发件人 ID 的 FCM 令牌之前未设置 APNS 设备令牌 '########'。不会发送到此 FCM 代币的通知 通过 APNS。确保在 APNS 设备后重新检索 FCM 令牌 令牌已设置。
添加了我在 AppDelegate 中的内容
import Firebase
import MasivPushIosSdk
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{
var firebaseToken: String = ""
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
self.registerForFirebaseNotification(application: application)
Messaging.messaging().delegate = self
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func registerForFirebaseNotification(application: UIApplication) {
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()
}
}
extension AppDelegate: MessagingDelegate, UNUserNotificationCenterDelegate {
//MessagingDelegate
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
self.firebaseToken = fcmToken!
print("Firebase token: \(fcmToken)")
}
//UNUserNotificationCenterDelegate
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("APNs received with: \(userInfo)")
}
}
【问题讨论】:
标签: ios firebase push-notification firebase-cloud-messaging access-token