ionic5 push notifications

ionic cordova plugin add phonegap-plugin-push --variable SENDER_ID="*********"
npm install @ionic-native/push


in config.xml
<resource-file src="google-services.json" target="app/google-services.json" />
in app.module.ts
import { Push} from '@ionic-native/push/ngx';
in providers add-->push
in app.component.ts
import { Push, PushObject, PushOptions } from '@ionic-native/push/ngx';
private push: Push,-->in constructor
ngOnInit(){
this.pushnotification();
}
pushnotification(){
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
this.sendmsg();
} else {
console.log('We do not have permission to send push notifications');
}
});
}
sendmsg(){
const options: PushOptions = {
android: {
senderID: '************'
},
}
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any)
=> console.log('Received a notification', notification));
pushObject.on('registration').subscribe((registration: any)
=> console.log('Device registered', registration));
pushObject.on('error').subscribe(error =>
console.error('Error with Push plugin', error));
}


Comments

Popular posts from this blog

Your app currently targets API level 27 and must target at least API level 28 to ensure it is built on the latest APIs optimized for security and performance. Change your app's target API level to at least 28

ionic project creation

change root user in ubuntu