Home / IOS Development / ios – Firebase Cloud Messaging cannot receive notification if it is updated from an existing App Store version

ios – Firebase Cloud Messaging cannot receive notification if it is updated from an existing App Store version



My app has FCM with message load setup and works successfully using APN̵

7;s Auth Key when running in Xcode debugging mode and when test subjects download release build from TestFlight. Both App Store ID and Team ID are also properly configured in Firebase project settings.

However, I found that if I install the app from the AppStore first (the building has similar GoogleService-Info.plist, but did not have full FCM features implemented yet), then override the building via TestFlight-build (this building has complete FCM features) the app can still receive the FCM token, but does not appear to receive any FCM messages. If I use Firebase’s Notification composer to send the message with the received token, the app can actually receive that notification, so this means that the APN must be set correctly.

I had searched for a similar problem and found this question which seems to have similar but still slightly different problem as mine. There is no answer though, so I still could not get any idea.

My question is, what can cause the FCM on the app to work differently when downloaded directly from TestFlight (which works well) and when “overridden” from the AppStore? My biggest concern is also whether FCM will work when finally the app is updated from AppStore old build to new build?

Some code settings related to receiving messages / notifications in AppDelegate. I omit the delegate’s setting code.

//Handle messages with method swizzling disabled
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

   func userNotificationCenter(_ center: UNUserNotificationCenter,
                          willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
       let userInfo = notification.request.content.userInfo
    
       os_log("didReceiveRemoteNotification: %{public}@", log: LogCategories.FCMSetup, type: .debug, userInfo)

       AppDelegate.getFcmClient().processMessaging(center, willPresent: notification, withCompletionHandler: completionHandler)

       // With swizzling disabled you must let Messaging know about the message, for Analytics
       Messaging.messaging().appDidReceiveMessage(userInfo)
    }

    // This is received when app is backgrounded and then reopen
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                          didReceive response: UNNotificationResponse,
                          withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        if let messageID = userInfo[FCMClient.gcmMessageIDKey] {
            print("Message ID: (messageID)")
        }
        os_log("didReceiveUserNotification: %{public}@", log: LogCategories.FCMSetup, type: .debug, userInfo)

        completionHandler()
    }

}

extension AppDelegate : MessagingDelegate {

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        // Note: This callback is fired at each app startup and whenever a new token is generated.
        AppDelegate.getFcmClient().setNewToken(fcmToken)
    
        let dataDict:[String: String] = ["token": fcmToken]
        NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
        os_log("Firebase registration token received: %{public}@", log: LogCategories.FCMSetup, type: .debug, fcmToken)
    }

    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
        AppDelegate.getFcmClient().processMessaging(messaging, didReceive: remoteMessage)
    }

}


Source link