Jeff Small
Jeff Small

Reputation: 91

Firebase Cloud Messaging Not Receiving Notification (iOS)

I am trying to use Firebase Notification Composer to send a test notification to my device. I am receiving an FCM token and printing it to my console, then I am trying to send a notification to that token.

Here is what I have checked:

1) I am on iOS 12.4.1

2) I am assigning the messaging delegate

3) I am receiving the FCM token from the delegate method

4) I have verified that notifications are enabled through printing to console, and when I was prompted to allow notifications I clicked allow

5) I have verified that in the Firebase project settings there is an APNs Auth Key uploaded, with a correct TeamID and KeyID

6) The delegate method willPresentNotifications is not called when I send the test message

7) I have tried with Swizzling enabled/disabled, neither work

8) There are no errors in debug

Here is the code:

import UIKit
import Firebase
import UserNotifications


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    UITabBar.appearance().barTintColor = UIColor(named: "Splish")!
    UINavigationBar.appearance().barTintColor = UIColor(named: "Splish")!
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

    FirebaseApp.configure()

    Messaging.messaging().delegate = self

    UNUserNotificationCenter.current()
        .requestAuthorization(options: [.alert, .sound, .badge]) {granted, error in

            print("Permission granted: \(granted)")
    }

    UNUserNotificationCenter.current().delegate = self

    application.registerForRemoteNotifications()

    return true
}


func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {

    print("FCM Token Is: \(fcmToken)")
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    print("Token is: \(deviceToken)")
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

    print("Error is \(error)")
}

Upvotes: 5

Views: 2870

Answers (1)

Mr. Disability
Mr. Disability

Reputation: 838

For iOS 14.4 using Swift, I used Firebase's example here.

With the help from @C6Silver suggesting to enable "Push Notifications" in Capabilities, I was then able to receive fcm test notifications.

Happy coding everyone!

Upvotes: -1

Related Questions