2017-01-31 20 views
1

Imは、最新のionic2リリースでプッシュ通知を実装しようと5秒後に解雇されていない、これはこのdoc以下の私のコードです:https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59#.2oe9zk3z5ionic2プッシュ通知エラー:デバイスは

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); 
    }); 
    } 
} 

と私は私のAndroidデバイス上でそれを実行したとき、私はすでにイオンのiCloud

FCMサーバキーとのSenderIDとセットアップを得たので、コンソールでこのエラーを与えると言う:

あなたがから変更することができます
[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

、イオン雲のプッシュ通知が持っていたのに役立ちます

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

希望:に

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

私が思う多くの問題は今修正されています。 – ADiL

答えて

0

:これは私はすでにOneSignal APIを使用してプッシュ通知をした