Open Emanuel-111 opened 1 month ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Thanks for reporting, @Emanuel-111. I tried to reproduce the issue, but I can't get the same error you encountered. May I know if you're still able to reproduce the issue? You may also try our sample app as your baseline for troubleshooting.
I did change the code a tad but yes, I can still reproduce the issue.
Give me some time and I can try to come up with a sample app
If you're still trying the code at the top, I left some relevant photos of what the firebase console, info and Google plists, and a blurred APN Auth Key to see if maybe I'm missing something
I was able to figure out the problem, its actually due to another method being called in another file.
private func subscribeToNotifications() { Messaging.messaging().subscribe(toTopic: "drivers") { error in if let error = error { print("Error subscribing to topic: \(error)") } else { print("Subscribed to topic: drivers") } } print("It skipped the subscribeToNotifications") }
When I subscribe to Notifications, the FCM error appears. Why would that be?
When I subscribe to Notifications, the FCM error appears. Why would that be?
https://github.com/firebase/firebase-ios-sdk/issues/10679#issuecomment-1402776795 may be relevant here, especially if you recently updated from a Firebase version before the change mentioned went into effect
It just might be, though, I notice when I call my reference.observe(.value) function it seems to skip over the function entirely, I'm not sure if that might be the issue
Description
A few days ago, Firebase was working like a charm, I had no issues with connecting to the server that I had connected to an iOS app. Then one day, I kept coming across this error
10.29.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID 'XXXXXXXXX'.Be sure to re-retrieve the FCM token once the APNS device token is set. It was cryptic to a whole new level. So I began searching for an answer as to why this was happening. After doing some debugging, I came across something odd.
For context:
The Firebase server is running Entitlement files are set to production (APS Environment and App Attest) FirebaseAppDelegateProxyEnabled is disabled but has been enabled at times I have AppCheck running well I have added the APN Auth Key to the appropriate spot I put the correct name in the Key ID and Team ID Same for the Bundle ID and Team ID for the app GoogleService.plist is in my app I had no prior issue with the server until September 21 at around 12pm No code in the AppDelegate was changed prior to September 21 Here's the portion of code it would run
//1. Called when the app is launched func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Then it runs some other method that is not in the AppDelegate and these print statements appeared
10.29.0 - [FirebaseInAppMessaging][I-IAM280002] Firebase In App Messaging was not configured with FirebaseAnalytics. 10.29.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '762004236193'.Be sure to re-retrieve the FCM token once the APNS device token is set. 10.29.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified 10.29.0 - [FirebaseMessaging][I-FCM002010] The subscription operation failed due to an error getting the FCM token: Error Domain=com.google.fcm Code=505 "No APNS token specified before fetching FCM Token" UserInfo={NSLocalizedFailureReason=No APNS token specified before fetching FCM Token}. Afterwards (with swizzling on), it runs these methods
Here's the print statements
Error subscribing to topic: The operation couldn’t be completed. No APNS token specified before fetching FCM Token 8th - Setting APNs Token 9th - Assigning APNs Token to deviceToken Device Token received: 32 bytes FCM token received: [The FCM token] FCM token: [The FCM token] Subscribed to newPickupRequest topic Based on the bebugging I made, it seems like some other method is being called in between both methods.
What could be the issue here? Is it a bug or glitch I'm not aware of?
In case needed, here the full class and the [NameofApp]App
import UIKit import UserNotifications import Firebase import FirebaseCore import FirebaseMessaging import TabularData
class DriverAppCheckProviderFactory: NSObject, AppCheckProviderFactory { func createProvider(with app: FirebaseApp) -> AppCheckProvider? { return AppAttestProvider(app: app) } }
class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate {
}
extension AppDelegate: UNUserNotificationCenterDelegate { // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions { let userInfo = notification.request.content.userInfo
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async { let userInfo = response.notification.request.content.userInfo
}
}
@MainActor class NotificationManager: ObservableObject{ @Published private(set) var hasPermission = false static let shared = NotificationManager()
}
extension Notification.Name { static let newPickupRequest = Notification.Name("newPickupRequest") }
@MainActor class NotificationHandler: NSObject, ObservableObject { @Published var newRequestAlert = false
}
class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
}
Here's the DriverLocationApp
import SwiftUI import FirebaseCore
@main struct DriverLocationApp: App {
// register app delegate for Firebase setup @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate private var Notedelegate: NotificationDelegate = NotificationDelegate()
var body: some Scene { WindowGroup { ContentView() } } }
Reproducing the issue
No response
Firebase SDK Version
11.2
Xcode Version
16.1
Installation Method
Swift Package Manager
Firebase Product(s)
App Check, Database, In-App Messaging, Messaging
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
Expand
Package.resolved
snippet```json Replace this line with the contents of your Package.resolved. ```
If using CocoaPods, the project's Podfile.lock
Expand
Podfile.lock
snippet```yml Replace this line with the contents of your Podfile.lock! ```