Reputation: 1881
I am using onesignal plugin for an app that I am developing in Ionic 2, the plugin is working. The messages sent from OneSignal are showing in the app but I have a problem when I try to get the player unique id:
This is the code that I use for showing messages, this code works:
let notificationOpenedCallback = function(jsonData) {
let alert =alertCtrl.create({
title: jsonData.notification.payload.title,
subTitle: jsonData.notification.payload.body,
buttons: ['OK']
});
alert.present();
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};
window["plugins"].OneSignal
.startInit("05d411f4-45da-4101-92a5-4a60e5c9fd03", "49543248748")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
and this code is for get Ids:
window["plugins"].OneSignal
.startInit("05d411f4-45da-4101-92a5-4a60e5c9fd03", "49543248748")
.endInit();
window["plugins"].OneSignal.getIds(function(ids){
firebase.database().ref('usuarios/'+ this.usuarioId).update({
idOnesignal: ids.userId
})
this code just does not run
Upvotes: 4
Views: 2880
Reputation: 1881
I fixed using ionic native onesignal:
import { OneSignal } from '@ionic-native/onesignal';
constructor(public one: OneSignal) {
this.bs = firebase.database().ref('/usuarios');
this.usuarioid = firebase.auth().currentUser.uid;
this.one.getIds().then((ids) => {this.one_id = ids.userId,
this.bs.child(this.usuarioid).update({idOneSignal: this.one_id})});
}
Upvotes: 6