我正在尝试从Firebase在我的项目中实现通知。我遵循了此处列出的所有步骤。但是,未发送测试消息。
https://firebase.google.com/docs/cloud-messaging/ios/certs
我已经在Apple Developer Account网站上完成了以下操作;
我已经实现了以下代码;
var apnsToken = Messaging.messaging().apnsToken
func registerNotifications() {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (isGranted, error) in
if error != nil {
print(error as Any)
return
} else {
switch isGranted {
case true:
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
case false:
print("Not Granted")
return
}
}
}
}
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
let dataDict:[String: String] = ["fcmToken": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
FirestoreService.shared.didReceiveRegistrationToken(withFCMToken: fcmToken)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("RESIGERED FOR REMOTE NOTIFICATIONS:", deviceToken)
NotificationService.shared.apnsToken = deviceToken
}
我已经确认我正在获取fcmToken,并且我也正在获取设备令牌数据。
但是,我没有收到任何通知。
一如既往的帮助,我们将不胜感激。
删除并重新安装了该应用程序,它可以正常工作。我不知道为什么。