0
votes

I am pulling my hair out, this problem is been bugging me for now a whole day. I created 3 projects and none of them seems to work. I just want to send some push notifications to my app, but I receive nothing. I triple checked the certificate files, recreated them, but it doesn't seem to do anything. Firebase is telling me that the notifications arrived, but I never see them in my logs/screen.

This is the relevant AppDelegate.swift file, although I have a full reproduction project here: https://github.com/Jasperav/NotificationTest/blob/master/Shared/AppDelegate.swift.

import UIKit
import Firebase

class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate,
    UNUserNotificationCenterDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions _: [
        UIApplication.LaunchOptionsKey: Any
        ]? =
        nil
    ) -> Bool {
        assert(Thread.isMainThread)

        print("Preparing to configure Firebase")

        // Ask the user to accept push notifications
        // This will be only asked once according to the docs
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current()
                .requestAuthorization(options: [
                    .alert,
                    .sound,
                    .badge,
                ]) { _, _ in
                    // This is not really important
                }

        UIApplication.shared.applicationIconBadgeNumber = 0
        UIApplication.shared.registerForRemoteNotifications()
        FirebaseApp.configure()
        Messaging.messaging().delegate = self

        return true
    }

    func messaging(
        _: Messaging,
        didReceiveRegistrationToken fcmToken: String?
    ) {
        print("New firebase registration token: \(String(describing: fcmToken))")
    }

    func userNotificationCenter(
        _: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        let userInfo = notification.request.content.userInfo

        print("Will present: \(userInfo)")
        
        completionHandler([.alert, .sound])
    }

    func userNotificationCenter(
        _: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping ()
        -> Void
    ) {
        let userInfo = response.notification.request.content.userInfo

        print("Did receive: \(userInfo)")

        completionHandler()
    }

    func application(
        _: UIApplication,
        didFailToRegisterForRemoteNotificationsWithError error: Error
    ) {
        print("Failed to register: \(error.localizedDescription)")
    }
}

And my @App View:

import SwiftUI

@main
struct NotificationTestApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

These are my log files:

Preparing to configure Firebase
2022-07-28 16:40:19.545648+0200 NotificationTest[1118:44117] 9.4.0 - [FirebaseAnalytics][I-ACS023007] Analytics v.9.4.0 started
2022-07-28 16:40:19.546132+0200 NotificationTest[1118:44117] 9.4.0 - [FirebaseAnalytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2022-07-28 16:40:19.549310+0200 NotificationTest[1118:44117] 9.4.0 - [FirebaseMessaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2022-07-28 16:40:19.558660+0200 NotificationTest[1118:44123] 9.4.0 - [FirebaseAnalytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-07-28 16:40:19.569110+0200 NotificationTest[1118:44118] 9.4.0 - [FirebaseAnalytics][I-ACS023012] Analytics collection enabled
2022-07-28 16:40:19.569226+0200 NotificationTest[1118:44118] 9.4.0 - [FirebaseAnalytics][I-ACS023220] Analytics screen reporting is enabled. Call Analytics.logEvent(AnalyticsEventScreenView, parameters: [...]) to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
New firebase registration token: Optional("dD9dhpXn-kwplReNcu0h9j:APA91bGQG1nfCzADmz2SO4iRORLpILyPw1ZsvFWA4rFQL45VymLPWlRmJ90asLHGldSeEfpw7l34kpMsgD9ngOIk6YrOursB2mmCmc8yEJDG9IvYWTFWq-HsHfHDc-rxKYr0j0oyeHkV")

I tried sending my FCM message through the console and also through the CLI. Both are telling me that it succeeded, but, as you can see above, the logs don't receive anything.

Capabilities:

enter image description here