Skip to content

Push Notifications Fail After App Reinstallation #14246

@JCsplash

Description

@JCsplash

Description

Description
After deleting and reinstalling the app, Firebase Cloud Messaging (FCM) push notifications fail to work until the app is quit and restarted once or twice. This issue seems to be related to the APNs token not being set before retrieving the FCM token.

Error Messages
The following errors are logged during the issue:
The operation couldn’t be completed. No APNS token specified before fetching FCM Token
APNS device token not set before retrieving FCM Token for Sender ID. Be sure to re-retrieve the FCM token once the APNS device token is set.
Declining request for FCM Token since no APNS Token specified

Steps to Reproduce

  1. Log in to the app and confirm that FCM notifications are working.
  2. Delete the app.
  3. Reinstall the app.
  4. Observe that FCM notifications do not work immediately after reinstallation.

If you quit and restart the app multiple times, the notifications begin to work.

Code Snippet
This is the code used to register for remote notifications:

func registerForRemoteNotifications() {
    let application: UIApplication = UIApplication.shared
    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = (application.delegate) as? AppDelegate

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }
    application.registerForRemoteNotifications()
}

Environment
Firebase SDK Version: Upgraded from 8.8.0 to 11.6.0
Xcode 16.1
Swizzling: Enabled
Push Notification Settings: Configured as per documentation
Expected Behavior
After deleting and reinstalling the app, push notifications should work immediately without requiring multiple restarts of the app.

Actual Behavior
Push notifications fail to work immediately after reinstalling the app. The following errors are logged until the app is restarted once or twice:

The operation couldn’t be completed. No APNS token specified before fetching FCM Token
APNS device token not set before retrieving FCM Token for Sender ID
Declining request for FCM Token since no APNS Token specified

This issue did not occur with Firebase SDK version 8.8.0 but surfaced after upgrading to version 11.6.0.

Reproducing the issue

Steps to Reproduce

  1. Log in to the app and confirm that FCM notifications are working.
  2. Delete the app.
  3. Reinstall the app.
  4. Observe that FCM notifications do not work immediately after reinstallation.

If you quit and restart the app multiple times, the notifications begin to work.

Firebase SDK Version

11.6.0

Xcode Version

16.1

Installation Method

CocoaPods

Firebase Product(s)

Messaging

Targeted Platforms

iOS

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!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions