Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCM plugin is not implemented on iOS #141

Closed
rodcts opened this issue Feb 23, 2023 · 1 comment
Closed

FCM plugin is not implemented on iOS #141

rodcts opened this issue Feb 23, 2023 · 1 comment

Comments

@rodcts
Copy link

rodcts commented Feb 23, 2023

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
Copy link
Contributor

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.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants