gpt4 book ai didi

javascript - Unhandled Promise rejection : push. on is not a function

转载 作者:数据小太阳 更新时间:2023-10-29 05:37:48 25 4
gpt4 key购买 nike

我正在使用 Ionic 2。

我在尝试设置推送通知时收到此 Typescrpt 错误。我从教程中复制了这个示例代码,所以我希望它能工作。我一定是出了什么问题。任何想法请:

Unhandled Promise rejection: push.on is not a function ; Zone: angular ; Task: Promise.then ; Value:
TypeError: push.on is not a function


push.on('registration', function (data) {

typescript

import { Push } from 'ionic-native';

..

  pushNotifications(): void {

var push = Push.init({
android: {
vibrate: true,
sound: true,
senderID: "xxxxxxxxxxxxxxxxxxx"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});

push.on('registration', (data) => {
console.log(data.registrationId);
alert(data.registrationId.toString());
});
push.on('notification', (data) => {
console.log(data);
alert("Hi, Am a push notification");
});
push.on('error', (e) => {
console.log(e.message);
});

}

最佳答案

确保在使用插件之前检查“window.cordova”是否可用。您实际上是在设备上还是在浏览器中进行测试? Cordova 在浏览器中不可用。

编辑为确保您的代码编辑器知道“window.cordova”是什么,请确保您安装了 cordova typings。

npm install typings -g
typings install dt~cordova --save --global

关于javascript - Unhandled Promise rejection : push. on is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39346571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com