Closed
Description
[REQUIRED] Step 1: Describe your environment
- Xcode version: 12.0.1
- Firebase SDK version: 6.34.0
- Firebase Component: Messaging
- Component version: 4.7.1
- Installation method:
CocoaPods
[REQUIRED] Step 2: Describe the problem
didReceiveRegistrationToken
is being called twice on first start after deleting and installing app. In that case, app is not receiving notifications. It is not happening, when this is first ever install on the particular device.
Steps to reproduce:
- Run app for the very first time on this device and
didReceiveRegistrationToken
is called once with token (as expected) - Delete app.
- Run app, freshly installed again and this time
didReceiveRegistrationToken
is called twice. First time with the token from previous installation. And a second later,didReceiveRegistrationToken
called again with new token. - In result is that, during that run app is not receiving notifications
- On each next run,
didReceiveRegistrationToken
is called once and all is good
If you have a downloadable sample project that reproduces the bug you're reporting, you will
likely receive a faster response on your issue.
Relevant Code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
application.registerForRemoteNotifications()
return true
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// With swizzling disabled you must let Messaging know about the message, for Analytics
//Messaging.messaging().appDidReceiveMessage(userInfo)
// Print full message.
print("did receive RN: \(userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
}
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token from message delegate: \(String(describing: fcmToken))")
// let dataDict:[String: String] = ["token": fcmToken ?? ""]
// NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
}