Earlier than encountering the error, I used to be utilizing Xcode which had Firebase put in. At round 12pm right now, I started encountering an error that regarded like this
APNS machine token not set earlier than retrieving FCM Token for Sender ID 'XXXX'. Make sure you re-retrieve the FCM token as soon as the APNS machine token is about.
Previous to 12pm, I didn’t encounter the error in any respect
After tinkering with it for 9 hours, I attempted shifting strategies round, regarded up many web sites to search out the precise error, debugging, and even went to YouTube of all locations, however cannot work out the place the error is coming from.
If it helps, I’m presently utilizing Xcode 16 with Firebase model 10.27.
This is the code for anybody who thinks they will discover the reply
That is in my AppDelegate from fixed debugging
For further context:
- I’ve the app operating on my iPhone 15 Professional Max and was operating properly earlier than the error
- I’ve Background Modes enabled (Background fetch, processing, distant notifications)
- In my Firebase Console, I’ve the APN key in my Cloud Messaging part
- I’ve added the app to my Firebase server
- I’ve the Google Information.plist in my code
- I’ve the app registred for App Attest (AppCheck) and DeviceCheck
// This technique will get referred to as when the app efficiently registers for distant notifications and receives a tool token from APNs
func software(_ software: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
Messaging.messaging().apnsToken = deviceToken
print("APNs Machine Token: (deviceToken)")
// Fetch the FCM registration token (this token is used to ship push notifications by Firebase)
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: (error)")
} else if let token = token {
print("FCM registration token: (token)")
}
}
}
// This technique known as when the app finishes launching
func software(_ software: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize Firebase
FirebaseApp.configure()
// Log app open occasion (for Firebase Analytics)
FirebaseAnalytics.Analytics.logEvent(AnalyticsEventAppOpen, parameters: nil)
// Set the delegate for Firebase Messaging
Messaging.messaging().delegate = self
// Register for distant notifications
software.registerForRemoteNotifications()
// Request notification authorization from the consumer
UNUserNotificationCenter.present().requestAuthorization(choices: [.alert, .sound, .badge]) { granted, error in
if granted {
DispatchQueue.predominant.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
// Set UNUserNotificationCenter delegate
UNUserNotificationCenter.present().delegate = self
return true
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let fcm = Messaging.messaging().fcmToken {
print("fcm", fcm)
}
}
func userNotificationCenter(_ heart: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
handleDailyReportTrigger()
completionHandler([.banner, .sound, .badge])
}