My app has FCM with message payload setup and work successfully using APNs Auth Key when running on Xcode debug mode and when downloading release build from TestFlight by testers. Both App Store ID and Team ID are set up correctly in Firebase project settings as well.
However I found that if I install the app from AppStore first (the build has corresponding GoogleService-Info.plist but didn't have complete FCM functionalities implemented yet), and then override the build via TestFlight build (this build has complete FCM functionalities), the app can still get FCM token but doesn't seem to receive any FCM messages. If I use Firebase's Notification composer to send message with the token received, the app can actually receive that notification so this means the APN should be set correctly.
I had searched to similar problem and found this question which seems to have similar but still a bit different issue as mine. There's no answer though so I still couldn't get any idea.
My question is, what may cause FCM on app works differently when downloaded directly from TestFlight (which works fine) and when "overriden" from AppStore ones? Also my biggest concern is if FCM will work when finally the app is updated from AppStore old build to the new build?
Some code settings relating to receiving messages / notifications in AppDelegate. I omit the delegate settings 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)
}
}