Trying to implement an alert using AlertController within an Ionic app inside the FCMPlugin.onNotification() function, but encountering issues where the alert controller is not being created. It seems that the method halts execution after the code for creating the alert.
pushNoteSetup(){
if(typeof(FCMPlugin) !== "undefined"){
FCMPlugin.getToken(function(t){
console.log("Use this token for sending device specific messages\nToken: " + t);
}, function(e){
console.log("Uh-Oh!\n"+e);
});
this.confirmAlert('Hi');
FCMPlugin.onNotification(
function(d){
if(d.wasTapped){
// Background receival (Even if app is closed),
// bring up the message in UI
let message = d['aps']['alert'];
console.log('Message received: ' + message);
this.alert = this.alertCtrl.create({
title: 'Hi',
message: 'Boo',
buttons: ['Ok']
});
this.alert.present();
console.log('Should have displayed an alert');
this.confirmAlert(message);
console.log('Skipping over alers?');
} else {
let message = d['aps']['alert'];
console.log('Message received: ' + message);
let alert = this.alertCtrl.create({
title: 'Hi',
message: 'Boo',
buttons: ['Ok']
});
alert.present();
console.log('Should have displayed an alert');
this.confirmAlert(message);
console.log('Skipping over alers?');
this.confirmAlert(message);
}
}, function(msg){
// No problemo, registered callback
console.log('Message:' + msg);
}, function(err){
console.log("Arf, no good mate... " + err);
});
} else {
console.log("Notifications disabled, only provided in Android/iOS environment");
}
}
public confirmAlert(message: any){
let mesg = String(message);
console.log('Message to display ' + mesg + ' and ' + message);
let confirmAlert = this.alertCtrl.create({
title: 'Alert',
message: message,
buttons: [{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('cancel');
}
}, {
text: 'Confirm',
handler: () => {
console.log('Confirm');
}
}]
});
confirmAlert.present();
}
This function is invoked after platform.ready() in app.componenet.ts