Capacitor: Failed to setup push Notifications for iOS

Created on 22 Mar 2020  路  9Comments  路  Source: ionic-team/capacitor

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?

Most helpful comment

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

All 9 comments

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

  1. Actually, when I followed the tutorial I faced an issue even in this place
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

  1. I've invited you to a private repository with a project so you could take a look.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gnesher picture gnesher  路  3Comments

mlynch picture mlynch  路  3Comments

json-derulo picture json-derulo  路  3Comments

peterpeterparker picture peterpeterparker  路  3Comments

alexcroox picture alexcroox  路  3Comments