Closed santekotturi closed 3 years ago
On the backend, here's the output from firebase admin messaging:
Sending message: {"notification":{"title":"Dev2 sent a new support message:","body":"does it work now"},"token":"869BBC83FC800D83F3AE62DBE674D33C5FA067586D791F6292CA6C4EB836353F" }
The registration token is not a valid FCM registration token {"code":"messaging/invalid-argument"}
Ok, this seems to fix it:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
} else if let result = result {
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: result.token)
}
}
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
I'm not expert in this level of the stack and I've just hacked this together from what was working with the new syntax.
I'd really appreciate it if someone could confirm that I can pass object: result.token
instead of object: deviceToken
to NotificationCenter.default.post(name: , object: )
without crashing things... ππΌ
@capacitor/push-notifications use APNS on iOS
if you want to use FCM we have a guide about how to do it, it has been updated for Capacitor 3
https://capacitorjs.com/docs/v3/guides/push-notifications-firebase#add-initialization-code
it includes how to pass the FCM token
It might be helpful to include a link to the above guide in the Capacitor 3 upgrade guide. I use firebase notifications in my iOS app and it caused issues when I followed along to the changes for notifications in AppDelegate.swift
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.
Bug Report
Capacitor Version
Platform(s)
Current Behavior
Registering push notifications return tokens that don't work with Firebase Cloud Messaging
Expected Behavior
Describe what the behavior should be. Tokens used to be in format:
eUh8TJmSCI0:APA91bHmp_2cZElJnKyRG9F-zZfGm6fa_Krv_MOy7z_2o2ZOo18VroSCxgAdUbWMSpwkMnkaTexViIHD-JygOflv_WvWisXsmbawbM_fNDenFuzDC....
Code Reproduction
.register()
:Other Technical Details
using the v3 plugin:
npm --version
output: 6.14.11node --version
output: v12.16.1pod --version
output (iOS issues only): 1.10.1Additional Context
Here's the cap sync output:
AppDelegate.swift:
Perhaps unrelated but the warning about the public folder not inside App/App seems misleading because in XCode I see: