capacitor-community / fcm

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

iOS notifications not working on iOS 14.4 #62

Closed Simbaclaws closed 3 years ago

Simbaclaws commented 3 years ago

Describe the bug Whenever I do exactly what has been mentioned in the documentation, I am unable to get notifications to show up on my iOS device.

This does work for android.

When I look at the logs I get these messages at the start of the app:

2021-03-17 17:08:05.664704+0100 App[514:45703] 6.24.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

2021-03-17 17:08:05.773091+0100 App[514:45709] 6.24.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.

2021-03-17 17:08:05.787817+0100 App[514:45709] 6.24.0 - [Firebase/Messaging][I-FCM002023] The object <FCM: 0x280e42700> does not respond to -messaging:didReceiveRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.
Loading network plugin

Then when I do the following:

import { FCM } from '@capacitor-community/fcm';
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, NotificationChannel } from '@capacitor/core';

const { PushNotifications, LocalNotifications } = Plugins;
const fcm = new FCM();

@Injectable({
  providedIn: 'root'
})
export class NotificationService {

  constructor() { }

  initNotifications() {
    PushNotifications.requestPermission().then( result => {
      if (result.granted) {
        PushNotifications.register().then((value) => {
          PushNotifications.addListener('registration',
          async (token: PushNotificationToken) => {
            console.log("Registration token APNS:", token);
            fcm
              .getToken()
              .then((fcmvalue) => {
                console.log("Registration token FCM:", fcmvalue.token);
              })
              .catch((error) => {
                console.error(error);
              });
            const data = await Promise.all([fcm.subscribeTo({ topic: 'news'}), fcm.subscribeTo({ topic: 'events'}), fcm.subscribeTo({ topic: 'test-channel'})]);
           });
        });
    }});
  }
}

I get the following logs:

⚡️  TO JS {"granted":true}
⚡️  To Native ->  PushNotifications register 67907362
⚡️  To Native ->  PushNotifications addListener 67907365
⚡️  TO JS {"value":"XXXXXXXXXXXXX"} <- same as below
⚡️  [log] - Registration token APNS: {"value":"XXXXXXXXXXXXX"}
⚡️  To Native ->  FCMPlugin getToken 67907369
⚡️  To Native ->  FCMPlugin subscribeTo 67907371
⚡️  To Native ->  FCMPlugin subscribeTo 67907372
⚡️  To Native ->  FCMPlugin subscribeTo 67907373
⚡️  TO JS {"token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"} <- same as below but not as above
⚡️  [log] - Registration token FCM: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
⚡️  TO JS {"message":"subscribed to topic news"}
⚡️  TO JS {"message":"subscribed to topic test-channel"}
⚡️  TO JS {"message":"subscribed to topic events"}

Now when I send a message to either the FCM token as a test message directly from FCM, or to the test-channel topic. There is no notification shown on iOS.

When I send this to the test-channel topic it does show up on android but not on iOS.

I am using the following versions of software:

"@capacitor-community/fcm": "^1.1.0",
"@capacitor/android": "^2.4.0",
"@capacitor/core": "^2.4.0",
"@capacitor/ios": "^2.4.0",
"@ionic/angular": "^5.5.5"

with the following ionic info:

❯ ionic info

Ionic:

   Ionic CLI                     : 6.12.3 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.5
   @angular-devkit/build-angular : 0.1102.3
   @angular-devkit/schematics    : 11.2.3
   @angular/cli                  : 11.2.2
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI   : 1.5.3
   @capacitor/core : 2.4.7

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)

Utility:

   cordova-res (update available: 0.15.3) : 0.14.1
   native-run (update available: 1.3.0)   : 0.2.8

System:

   ios-deploy : 1.9.4
   NodeJS     : v15.7.0 (/usr/local/Cellar/node/15.7.0/bin/node)
   npm        : 7.4.3
   OS         : macOS Big Sur
   Xcode      : Xcode 12.4 Build version 12D4e

I have notifications enabled on iOS and allowed for the specific app that I'm using.

I'm using version 14.4 of iOS

To Reproduce Steps to reproduce the behavior:

  1. create an app using ionic
  2. follow the instructions on firebase to setup an app for fcm and follow the documentation on this community plugin's readme.
  3. Use the correct code and test it on an actual device by sending messages from fcm.

Expected behavior I expect iOS to receive the notification from fcm.

Smartphone:

Additional context I don't know whether it's normal to get these first messages on startup, I've looked at the code of the capacitor-community/fcm plugin and it clearly calls Firebase.configure and all the other stuff. Yet, it is complaining about this on startup. Could it be that there is some kind of conflict somewhere? Or is this normal behaviour?

That seems to be the only thing I could think of that would make this not work. Otherwise everything seems fine (console logs show the correct information)

I'm thinking about re-adding the platform with ionic capacitor add ios... But this requires me to check if all the native configs of all of my native functionality still works.

We used to use capacitor-fcm from npm (the deprecated version), which has worked in previous versions of the app. But because we've upgraded from ionic 4 to 5 and upgraded angular from 7 to 11, we needed to also upgrade this deprecated plugin to the capacitor-community/fcm plugin. Which is now giving us these issues.

Note: I've already cleaned the build folder and did a npx cap sync and npx cap copy ios... This is defined in my build script by default so shouldn't give me issues.

Simbaclaws commented 3 years ago

OK,

Apparently I did not check my auth keys on iOS firebase, since they were missing after we've switched to a different app id. This caused firebase to only send messages to android and not to iOS.

The messages were correct about registering to FCM, it was just that we had lost our auth key after changing our app id. Sorry for all of this, this issue can be closed.