I'm using firebase since ever, but today I was implementing push notifications to a new project, but it's not receiving notifications from FB Console
at all.
FCM Token is generated successfully.
APNs Key is uploaded
FirebaseAppDelegateProxyEnabled is set to NO
GoogleService-Info is integrated
I'm Using the following code inside AppDelegate didFinishLaunchingWithOptions
FirebaseApp.configure()
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
application.registerForRemoteNotifications()
}
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM registration token: \(token)")
}
}
Messaging Delegate
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
_ = notification.request.content.userInfo
completionHandler([.alert , .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
_ = response.notification.request.content.userInfo
completionHandler()
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
}
NOTE The following output appears when launching the app if it's gonna help
APNS device token not set before retrieving FCM Token for Sender ID 'XXXXXXXX'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retr
Thanks