capacitor-community / fcm

Enable Firebase Cloud Messaging for Capacitor apps
https://capacitor.ionicframework.com/docs/
MIT License
238 stars 83 forks source link

FCM plugin is not implemented on iOS #141

Closed rodcts closed 1 year ago

rodcts commented 1 year ago

Hey, guys, In my ionic/angular project, apparently I'm following the steps in the documentation, but when I run the application I see in the ios logs the error message "Error: Plugin "FCM" is not implemented in ios".

The notification for Android happens normally, but for iOS I get this error.

My package versions

"@capacitor-community/fcm": "2.0.2",
"@capacitor/android": "2.0.0",
"@capacitor/core": "2.0.0",
"@capacitor/ios": "2.0.0",

My imports


import { Platform } from '@ionic/angular';
import { Injectable } from '@angular/core';
import {
   Plugins,
   PushNotification,
   PushNotificationToken,
   PushNotificationActionPerformed
} from '@capacitor/core';
import { Store } from '@ngxs/store';
import { UtilitySet } from '../actions/utility.actions';
import { FCM } from '@capacitor-community/fcm';

My implementation

@Injectable({
  providedIn: 'root'
})
export class FirebasePushService {
  PushNotifications = Plugins.PushNotifications;
  constructor(
    private platform: Platform,
    public store: Store
  ) { }

  public value: string;

  register() {
    if (!this.platform.is('capacitor')) {
      console.log('Platform not registered on push notification');
      return;
    }
    this.PushNotifications.register();
    this.PushNotifications.addListener('registration',
      async (token: PushNotificationToken) => {
        try {
          console.log('Push registration success, token: ' + token.value);
          if (this.platform.is('ios')) {
            const token = await FCM.getToken()
            return token;
          }
          const {value} = token
          Plugins.MCareAdsManager.registerForPushNotification({ token: value, fcmToken: value });
          this.store.dispatch(new UtilitySet({
            firebaseToken: value
          }));
        } catch (error) {
          console.log('Error ', error);
        }
      }
    );
    this.PushNotifications.addListener('registrationError',
      (error: any) => {
        console.log('Error on registration: ' + JSON.stringify(error));
      }
    );
    this.PushNotifications.addListener('pushNotificationReceived',
      (notification: PushNotification) => {
        const options = { notification: notification.data.notification, trackingId:notification.data.TRAKING_ID, type:notification.data.type, appId:notification.data.ngtAppId, message:notification.data.alert };
        Plugins.MCareAdsManager.handleNotification(options);
        console.log('Push received: ' + JSON.stringify(notification));
      }
    );
    // Method called when tapping on a notification
    this.PushNotifications.addListener('pushNotificationActionPerformed',
      (notification: PushNotificationActionPerformed) => {
        console.log('Push action performed: ' + JSON.stringify(notification));
      }
    );
  }
}
jcesarmobile commented 1 year ago

If you are using Capacitor 2 you should be using version 1.x of the plugin version 2.x of the plugin is for Capacitor 3 version 3.x of the plugin is for Capacitor 4

You should consider updating to Capacitor 4 and version 3.x of the plugin, since fixes are not being backported to older versions.