firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Cloud Messaging no FCM token being created

Open ian-sayles opened this issue 4 months ago • 4 comments

Description

When I deploy my app to the App Store or TestFlight I no longer get any FCM tokens, works perfectly when running on connected device from within Xcode. Also no issue with Android version of my app, works ok in development and from the released app in Play Store.

Reproducing the issue

The App delegate:

final class AppDelegate: NSObject, UIApplicationDelegate {

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
       
    FirebaseApp.configure()
    Messaging.messaging().delegate = self
    UNUserNotificationCenter.current().delegate = self

    let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]

    UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
        if let error = error {
            print("Error requesting notification authorization: \(error)")
        } else if granted {
            print("Notification authorization granted")
        } else {
            print("Notification authorization denied")
        }
    }
    
    application.registerForRemoteNotifications()
    return true
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  print("Failed to register for remote notifications with error: \(error)")
}

}

This following code is never fired when the app is from the App Store or TestFlight, in the full code I save the token so can be used in other parts of the app:

extension AppDelegate: MessagingDelegate { @objc func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { guard let token = fcmToken else { return }

    }

}

Firebase SDK Version

10.23.0

Xcode Version

15.3 (15E204a)

Installation Method

Swift Package Manager

Firebase Product(s)

Messaging

Targeted Platforms

iOS, macOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet

Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet

Replace this line with the contents of your Podfile.lock!

ian-sayles avatar Mar 26 '24 12:03 ian-sayles

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Mar 26 '24 12:03 google-oss-bot

Thanks for reporting, @ian-sayles. Could you confirm if you've set the APS Environment key to production instead of sandbox/development in the Entitlements file?

rizafran avatar Mar 27 '24 18:03 rizafran

Thanks @rizafran I checked by entitlement file and it was set for development, edited the file and changed it production, submitted new app and tried it in TestFlight with same issue, I also checked the entitlement file to make sure Xcode had not changed it back, and it was still set for production.

ian-sayles avatar Mar 28 '24 12:03 ian-sayles

Thanks for the update, @ian-sayles. May I know if you have uploaded your production APNs certificate to the Firebase console?

rizafran avatar Apr 05 '24 14:04 rizafran

Thanks @rizafran I have used the APNs Authentication Key not the APN certificate, do you have to use the certificate or should it work with just the authentication key?

ian-sayles avatar Apr 09 '24 16:04 ian-sayles

@ian-sayles, you can use either the APNs authentication key or APNs certificate.

rizafran avatar Apr 12 '24 16:04 rizafran

Hey @ian-sayles. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Apr 19 '24 01:04 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@ian-sayles if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Apr 26 '24 01:04 google-oss-bot