簡體   English   中英

未處理的Promise拒絕:push.on不是一個函數

[英]Unhandled Promise rejection: push.on is not a function

我正在使用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) { 

打字稿

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類型。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM