capacitor-community / capacitor-community/fcm
Failed to get instance FirebaseID
- Dominant language
- TypeScript
- Stars
- 272
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
We are experiencing a weird token retrieval issue with error `Failed to get instance FirebaseID` when calling `FCM.getToken()` on iOS. Coming from: https://github.com/capacitor-community/fcm/blob/2cbc9169b150b34db25fb8c463d422feefc13ecd/ios/Plugin/Plugin.swift#L67
Does anybody have an idea what can be the cause of this error(I understand it could be many things) and is there anything that can be done?
The Android at the same time has no issue, only iOS it getting the error.
The `AppDelegate.swift` file is configured according to documentation https://capacitorjs.com/docs/guides/push-notifications-firebase#ios:
```swift
import UIKit
import Capacitor
import FirebaseCore
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
//... other methods ...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().token(completion: { (token, error) in
if let error = error {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
} else if let token = token {
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
}
})
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
```
With `Podfile` correctly containing `FirebaseMessaging` pod dependency:
```ruby
target 'App' do
capacitor_pods
# Add your Pods here
pod 'FirebaseMessaging'
end
```
Could it be that we are still missing something in the configuration and thus Firebase not getting instantiated properly?
Contributor guide
Research direction
Start with ios/Plugin/Plugin.swift at the linked line, then compare the reported AppDelegate.swift and Podfile configuration with the Capacitor Firebase push-notifications documentation. Reproduce the iOS FCM.getToken() failure and trace whether FirebaseMessaging is initialized and receiving the APNs token. Done means identifying a specific missing configuration or cause and documenting the required correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100