Unable to receive IOS notifications from Firebase Console
Asked Answered
H

1

9

I am stuck on pushing notifications to users. In Xcode, I receive any and all notifications sent from Firebase. However, when pushed to the App Store, I no longer receive them.

It says on firebase that X amount are sent but zero received/open.

Here is my app delegate:

    Did Finish Launching:

    //Firebase Integration
    FirebaseApp.configure()
    FirebaseConfiguration.shared.setLoggerLevel(.min)

    //Enabling push notifications
    registerForPushNotifications()

    //Handle Notification
           
    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)
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
      application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()
    
    Messaging.messaging().delegate = self

Here is the general app delegate with its contents.

  General App Delegate:

    //Register for Push Not.
    func registerForPushNotifications() {
    UNUserNotificationCenter.current()
      .requestAuthorization(
        options: [.alert, .sound, .badge]) { [weak self] granted, _ in
        print("Permission granted: \(granted)")
        guard granted else { return }
        self?.getNotificationSettings()
      }
}
        //Get Settings
        func getNotificationSettings() {
  UNUserNotificationCenter.current().getNotificationSettings { settings in
    print("Notification settings: \(settings)")
    
    guard settings.authorizationStatus == .authorized else { return }
    DispatchQueue.main.async {
      UIApplication.shared.registerForRemoteNotifications()
    }
  }
} 

    //Get the token
    func application(
  _ application: UIApplication,
  didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
  Messaging.messaging().apnsToken = deviceToken
}

Here are some extension functions. Not sure I need them.

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler:
@escaping (UNNotificationPresentationOptions) -> Void
 ) {
if #available(iOS 14.0, *) {
    completionHandler([[.banner, .sound]])
} else {
    // Fallback on earlier versions
}
}

 func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
 ) {
  completionHandler()
 }
}



 extension AppDelegate: MessagingDelegate {
 func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
 ) {
let tokenDict = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
  name: Notification.Name("FCMToken"),
  object: nil,
  userInfo: tokenDict)
  }
 }
Hornstein answered 25/1, 2022 at 4:11 Comment(0)
L
13

Go to firebase->Project Settings->Cloud Messaging -> then scroll down to Apple app configuration and make sure you've provided APNs Production Certificate or not, if not then generate production certificate and upload it there. Alternatively i suggest you to upload APNs Authentication Key instead of certificates.

Preview Image

Loge answered 25/1, 2022 at 4:57 Comment(3)
What changed? This option is not available to meAsterisk
Just to add to this, if you generate a new key: SAVE it somewhere. Apple does not allow you to download it again in the future. Also, Apple only allows you to make 1 key, so it is shared for all of your apps - adding a new app means using the same key (or replacing the key or all your apps if you have lost it).Leadsman
Worked for me, you get to see your keys on Certificates, Identifiers & Profiles on developer apple page: developer.apple.com/account/resources/authkeys/listFridell

© 2022 - 2024 — McMap. All rights reserved.