I do not know well the steps that you have followed to activate the notifications, I mention them quickly the sequence to follow, to locate if any of them has been missing:
Create the authentication key
In the Apple developer account, go to Certificates, Identifiers & Profiles, and in Keys select All.
Click on the add (+) button in the upper right corner.
Enter a description for the key.
In Key Services, select the APNs checkbox and click Continue.
Click Confirm and then Download. Keep the key in a safe place.
Install the authentication key in firebase
In the firebase project, select the gear icon and click Settings.
Go to Cloud Messaging
In the iOS setup in the APN Authentication Key, select Upload.
Configure the AppID
Go to your developer account - > App IDs and select the corresponding AppID, click Edit
In the services select the Push Notifications checkbox.
Click Done.
Add notifications to your project
In XCode enable push notifications in App> Capabilities.
If you mark an error in the provisioning profile, download it again because it was updated with the notification features.
Install the SDK
Add the pods to install in the PodFile as follows: pod 'Firebase / Core'pod' Firebase / Messaging '
Run pod install
Close and open the xcode project again.
In the AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Use Firebase library to configure APIs
FirebaseApp.configure()
//TODO Confirm if this is the right point to initialize Push Notifications
// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]
// Register for remote notifications. This shows a permission dialog on first run, to
// show the dialog at a more appropriate time move this registration accordingly.
// [START register_for_notifications]
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 {
// iOS 9 or before
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
// [END register_for_notifications]
return true
}
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID iOS10: \(messageID)")
}
// Change this to your preferred presentation option
completionHandler(.alert)
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("NOTIFICATION: Registration token => \(fcmToken)")
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("NOTIFICATION: Received data message => \(remoteMessage.appData)")
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("[RemoteNotification] didRefreshRegistrationToken: \(fcmToken)")
}
}