I followed the steps described in
https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/
According to recommendations, I've changed my didRegisterForRemoteNotificationsWithDeviceToken code in AppDelegate.swift as follows:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
Messaging.messaging().apnsToken = deviceToken
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
} else if let result = result {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)
}
}
}
However, I'm getting an error
Static member 'instanceID' cannot be used on instance of type 'InstanceID'
Could I get any help on this?
I just followed the tutorial the other day and didn't face this problem.
Can you provide a sample app?
I just made a few changes the other day, needed for Capacitor 2.0, but they are not published yet, you can check the file that generates the docs here
https://github.com/ionic-team/capacitor/blob/master/site/docs-md/guides/push-notifications-firebase.md
PushNotifications.requestPermission().then( result => {
if (result.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
Because PushNotifications.requestPermission method does not exist and I had to move to PushNotifications.register(); directly but anycase this seems to be overcamed
Thanks in advance for your help
Looking forward to hearing from you soon.
Capacitor 2.0 is still in beta, you can install it using next tag
i.e.
npm install @capacitor/ios@next
(Also for core and cli)
You have not committed ios folder, that's what I'm interested in
So all these instructions are for capacitor 2.0? Not for 1.5?
However, anycase my problem (as I understand) is related to AppDelegate.swift and Firebase pod. This should not relate to capacitor I think
iOS folder also pushed to the project now
The requestPermission method is new in Capacitor 2.0, the other things didn't change.
I thought latest doc changes weren't published, but I had a cached version.
The requestPermission method is new in Capacitor 2.0, the other things didn't change.
I thought latest doc changes weren't published, but I had a cached version.
ok, any case, this is not critical for now
This error:
Static member 'instanceID' cannot be used on instance of type 'InstanceID'
in AppDelegate.swift looks much more important
Your problem is you have phonegap-plugin-push installed, that is using a very old version of Firebase Messaging (2.x, while latest is 4.x).
So uninstall the plugin and run npx cap sync ios
Thanks a ton! It built successfully
Appreciate your help
Most helpful comment
Your problem is you have
phonegap-plugin-pushinstalled, that is using a very old version of Firebase Messaging (2.x, while latest is 4.x).So uninstall the plugin and run
npx cap sync ios