Hi everyone
I’m using / trying to use Ionic Native Push with Firebase Cloud Messaging.
(I believe) I correctly installed the Ionic Native Push Plugin.
At least when I tested sending push notifications it worked on Android.
Here is my code:
import { Injectable } from '@angular/core';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { AlertController } from 'ionic-angular';
@Injectable()
export class FcmProvider {
constructor(private push: Push,
private alertCtrl: AlertController) {
this.getPermission();
}
getPermission() {
this.initPush();
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');
this.presentErrorAlert();
}
});
}
private initPush() {
const options: PushOptions = {
android: {},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
console.log('Received a notification', notification);
this.presentSuccessAlert(notification.message);
});
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
private presentErrorAlert(): void {
let errorAlert = this.alertCtrl.create({
title: "Error",
subTitle: "Wir bekamen kein Token.",
buttons: ["Mies..."]
});
errorAlert.present();
}
private presentSuccessAlert(message: string): void {
let alert = this.alertCtrl.create({
title: "Neue Benachrichtigung",
message: message,
buttons: [
{
text: "Abbrechen",
role: "cancel",
handler: () => {
console.log("Cancel clicked");
}
},
{
text: "Ansehen",
handler: () => {
console.log("Show clicked");
}
}
]
});
alert.present();
}
}
And when I use XCode to debug on iOS I get the following messages:
Push Plugin VoIP missing or false
Push Plugin register called
PushPlugin.register: setting badge to false
PushPlugin.register: clear badge is set to 0
PushPlugin.register: better button setup
FCM Sender ID <my-id>
Using FCM Notification
4.11.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.
4.11.0 - [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40100000 started
4.11.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)
4.11.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.
FCM Registration Token: <my-token>
We have permission to send push notifications
Push Plugin register success: <some-id>
Device registered [object Object]
So as far as I’m concerned everything seems to work fine. Any help on why the push notifications don’t come through would be much appreciated!