我想向特定用户发送通知,我可以获取ID,但是当我尝试向这些ID发送通知时,我的工作无效。 在android中不发送成功或错误通知,并且ios发送" index.html null"通知。
通知从我发送它们的地方到达同一设备,没有一个到达我想要发送它们的设备。
这是app.component.js:
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();
});
并使用此代码发送de notification
window['plugins'].OneSignal.getIds(function(ids) {
let notificationObj = { contents: {"en": "Han hecho un nuevo pedido"},
heading: { "en": "Domi-Trustik" },
include_player_ids: [this.idadmin]
};
window['plugins'].OneSignal.postNotification(notificationObj,
function(successResponse) {
console.log("Notification Post Success:", successResponse);
alert("enviado:" + JSON.stringify(successResponse));
},
function (failedResponse) {
console.log("Notification Post Failed: ", failedResponse);
alert("error" + JSON.stringify(failedResponse));
}
);
});
在Ionic 2中
答案 0 :(得分:0)
与我的其他信号问题相同的错误,插件对某些功能无效,因此更好地使用原生离子版本:
import { OneSignal } from '@ionic-native/onesignal';
constructor(public one: OneSignal)
this.one.getIds().then((ids) => {
let notificationObj = {
include_player_ids: [this.idadmin],
contents: {en: "Han hecho un nuevo pedido"}};
window['plugins'].OneSignal.postNotification(notificationObj,
function(successResponse) {
console.log("Notification Post Success:", successResponse);
alert("enviado:" + JSON.stringify(successResponse));
},
function (failedResponse) {
console.log("Notification Post Failed: ", failedResponse);
alert("error" + JSON.stringify(failedResponse));
}
);
});