Skip to content

Messages not received when registration is done after first app launch #254

Closed
@pfrischmuth

Description

@pfrischmuth

Environment

  • Xcode version: 8.3.3 (8E3004b)
  • Firebase SDK version: 4.1.1 (happens starting from 4.0.0)
  • Library version: FirebaseMessaging 2.0.2
  • Firebase Product: messaging

Describe the problem

Steps to reproduce:

When I register for push notifications directly when the app starts for the first time (after install), the registration process works and I can send a notification to my device via the Firebase console.

However when I do not register on first app launch (i.e. launching the app for the first time, stopping it and register on second launch), the registration process seems to succeed (I can access the FCM token), but when I send a message via the Firebase console to that token, I will not receive the message.

When I use (almost) the same code (changes only in the commented out lines, due to changes to the API) with a Firebase version <4.0.0 (e.g. Firebase 3.15.0), both cases work fine.

Relevant Code:

I created a very simple project that reproduces the problem. I comment out the code for the first launch and then do the registration on the second launch, which produces the issue.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    // use the following line for Firebase < 4.0.0
    //FIRApp.configure()

    // START: comment out the following block on first app launch
    UNUserNotificationCenter.current().delegate = self

    let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(
        options: authOptions,
        completionHandler: {_, _ in })

    application.registerForRemoteNotifications()

    let token = Messaging.messaging().fcmToken
    // use the following line for Firebase < 4.0.0
    //let token = FIRInstanceID.instanceID().token()
    print("FCM token: \(token ?? "")")
    // END

    return true
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions