Push notifications with Firebase on iOS


#1

I’ve used these instructions to setup Push notifications with Firebase on iOS. I’m pretty sure I’ve setup all the Apple certificates correctly and I can sent the notifications from FCM (Firebase Cloud Messaging) just fine, and the status is “sent”, but they never arrive in my iPhone.

Here’s my code. Any advice why this is not working or how to debug it will be highly appreciated!! Many thanks!

import { Push, PushObject, PushOptions } from '@ionic-native/push';

constructor(platform: Platform, private push: Push, public alertCtrl: AlertController) {
    platform.ready().then(() => {
      StatusBar.styleDefault();
      Splashscreen.hide();
      this.pushNotifications();
    });
  }
  pushNotifications() {
    this.push.hasPermission().then((res: any) => {
      if (res.isEnabled) { console.log('We have permission to send push notifications');}
      else { console.log('We do NOT have permission to send push notifications'); }
    }).catch((error) => { console.log("Push Notification needs Cordova: " + JSON.stringify(error));});

    const options: PushOptions = {
      android: {
        senderID: 'My_ID'
      },
      ios: {
        alert: 'true',
        badge: true,
        sound: 'false'
      },
      windows: {}
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject.on('notification').subscribe((notification: any) => {
      if(notification.additionalData.foreground) {
        let youralert = this.alertCtrl.create({
          title: 'New Push notification',
          message: notification.message
        });
        youralert.present();
      }
    });

    pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
    pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
  }

#2

Did you figure it out?


#3

Yes, the problem was very simple. You MUST do any of these two:

  1. Have authenticated users use/test your app (FireAuth)
  2. Get a paid subscription to Firebase

The problem here is with Firebase, it doesn’t allow free account to sent push notifications to unauthorised users.


#4

But that is not mentioned anywhere!


#5

Well, it’s mentioned in the prices table when you consider to upgrade to a paid account. but otherwise yes, so I’ve wasted a good half-day on this issue, so can feel your paid.