2017-01-31 45 views
1

我試着去實施最新發布ionic2推送通知後一直沒有解僱,這是繼該文檔我的代碼:https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59#.2oe9zk3z5ionic2推送通知的錯誤:設備5秒

app.component.ts

import { Component, ViewChild } from '@angular/core'; 
import { Platform, Nav, AlertController } from 'ionic-angular'; 
import { StatusBar, Splashscreen, AdMob, Push } from 'ionic-native'; 

import { HomePage } from '../pages/home/home'; 
import { Config } from '../providers/config'; 

import { DownloadPage } from '../pages/download/download' 

@Component({ 
    templateUrl: 'app.html' 
}) 
export class MyApp {  
    @ViewChild(Nav) nav: Nav; 
    rootPage = HomePage; 

    constructor(public platform: Platform, public conf: Config, public alertCtrl: AlertController) { 

    platform.ready().then(() => { 
     StatusBar.styleDefault(); 
     Splashscreen.hide(); 

     AdMob.createBanner({adId : this.conf.admobBanner, isTesting:true}).then(() => { AdMob.showBanner(8); }); 

     this.initPushNotification(); 


    }); 

    } 

    initPushNotification(){ 
    if (!this.platform.is('cordova')) { 
     console.warn("Push notifications not initialized. Cordova is not available - Run in physical device"); 
     return; 
    } 
    let push = Push.init({ 
     android: { 
     senderID: "xxxxxx" // I have senderID 
     }, 
     ios: { 
     alert: "true", 
     badge: false, 
     sound: "true" 
     }, 
     windows: {} 
    }); 

    push.on('registration', (data) => { 
     console.log("device token ->", data.registrationId); 
     //TODO - send device token to server 
    }); 
    push.on('notification', (data) => { 
     console.log('message', data.message); 
     let self = this; 
     //if user using app and push notification comes 
     if (data.additionalData.foreground) { 
     // if application open, show popup 
     let confirmAlert = this.alertCtrl.create({ 
      title: 'New Notification', 
      message: data.message, 
      buttons: [{ 
      text: 'Ignore', 
      role: 'cancel' 
      }, { 
      text: 'View', 
      handler:() => { 
       //TODO: Your logic here 
       self.nav.push(DownloadPage); 
      } 
      }] 
     }); 
     confirmAlert.present(); 
     } else { 
     //if user NOT using app and push notification comes 
     //TODO: Your logic on click of push notification directly 
     self.nav.push(DownloadPage); 
     console.log("Push notification clicked"); 
     } 
    }); 
    push.on('error', (e) => { 
     console.log(e.message); 
    }); 
    } 
} 

,我已經得到了FCM服務器密鑰和Sender ID和設置離子的iCloud

所以,當我在我的Android設備上運行它,它說給在控制檯中的錯誤:

[14:41:35] console.log: deviceready has not fired after 5 seconds. 
[14:41:35] console.log: Channel not fired: onPluginsReady 
[14:41:35] console.log: Channel not fired: onCordovaReady 
[14:41:36] error opening ws message: {"category":"console","type":"log","data":["DEVICE READY FIRED AFTER",4182,"ms"]} 
[14:41:47] error opening ws message: {"category":"console","type":"log","data":["device token 
      ->","cJ5Iw6b9OpW:APA91bHmplWN80qKFld0wtcfnFCmO5kjFHj1tuCwMkCOMKYcZ-HbMC4i7Vg1hIbdL9d0eDdl2c7MWsJ79XrLQ3m4cnEwj6I7E3s2eDO58yrqg9C_xGsLkLWYWQ"]} 
+0

我已經沒有使用OneSignal API推送通知,推送離子云的通知已經有那麼我認爲現在已經解決了很多問題。 – ADiL

回答

0

你可以改變從:

console.log("device token ->", data.registrationId); 

到:

console.log("device token:"); 
console.log(JSON.stringify(data)); 

希望這有助於