Ric*_*ard 6 javascript typescript ionic-framework ionic2 angular
我正在使用Ionic 2.
尝试设置推送通知时,我收到此Typescrpt 错误.我已从教程中复制了此示例代码,因此可以预期它可以正常工作.我一定有错.任何想法请:
Run Code Online (Sandbox Code Playgroud)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) {
打字稿
import { Push } from 'ionic-native';
Run Code Online (Sandbox Code Playgroud)
..
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);
});
}
Run Code Online (Sandbox Code Playgroud)
在使用插件之前,请务必检查“window.cordova”是否可用。您实际上是在设备上还是在浏览器中进行测试?Cordova 在浏览器中不可用。
编辑为了确保您的代码编辑器知道“window.cordova”是什么,请确保您安装了cordova类型。
npm install typings -g
typings install dt~cordova --save --global
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1123 次 |
| 最近记录: |