2017-07-04 8 views
0

以前はIonic cloudを使用していました。PUSHなどすべて正常に機能していました。今私は私のサーバーからそれを管理したい。IONIC 2ネイティブプッシュ通知リダイレクトも表示もしません

phonegap-plugin-pushは、IONICクラウドプッシュで使用されていたので、送信者ID付きです。

push.on('registration', (data) => { 

    // SAVE TO Server 
     this.device_details.device_token = data.registrationId; 
     var form = new FormData(); 
     form.append("user_device_token", this.device_details.device_token); 
     form.append("user_device_type", this.device_details.device_type); 
     //console.log(form); 
     this.webService.saveToken(form) 
     .subscribe(response => { 
      console.log(response.message); 
     }, error => { 
      console.log("Oooops!" + error); 
     }); 
    // SAVE TO Server 
}); 
- :ネイティブPUSH輸入

:以下

let push = Push.init({ 
     android: { 
     icon: "blicon", 
     iconColor: "#AE2829", 
     senderID: Config.fcmSenderID 
     }, 
     ios: { 
     alert: "true", 
     badge: "true", 
     sound: "true" 
     }, 
     windows: {} 
}); 

デバイストークンが正常に動作し、サーバーに保存されてきている方法である:以下

import { StatusBar, Splashscreen, GoogleAnalytics, Push } from 'ionic-native'; // Native Push 

は私がPUSHを開始した方法です

これまで想定されていたものがすべて動作していて、自分の端末でプッシュ通知を受信できるようになりました。受信したプッシュパラメータを処理します。

push.on('notification', function(data) { 
    if(data.additionalData.foreground == false) { 
     this.nav.push(DetailPage, {id: data.additionalData.pageid}); 
    } else { 
     let confirm = this.alertCtrl.create({ 
      title: data.title, 
      message: data.message, 
      buttons: [ 
      { 
       text: 'Check Later', 
       role: 'cancel' 
      }, 
      { 
       text: 'Check Now', 
       handler:() => { 
       if(data.additionalData.postid !== undefined) { 
        this.nav.push(DetailPage, {id: data.additionalData.pageid});     
       } 
       } 
      } 
      ] 
     }); 
     confirm.present(); 
    } 

私はそれが私がペイロードを送信するすべての値をpop'upsが、他に何も起こりませんALERTコマンドを使用しようとするたびに。

IDパラメータの詳細ページには移動せず、Alertcontrolボックスも表示しません。

この問題を解決するのを手伝ってください。 Android用 トークンデバイスを生成するイオン2アプリケーションの設定のおかげSanny

+0

以下のURL https://stackoverflow.com/questions/44605734/how-to-send-push-notification-with-angularjs-and-cordova-fcm/44605950#44605950を使用してください –

答えて

0

は、FCMのセットアップ手順に従ってください。それはあなたにSERVER_KEYとSENDER_IDを与えます。 SERVER_KEYはサーバーがプッシュ通知を送信するために使用され、SENDER_IDはデバイスがデバイストークンを生成するために使用します。 iOSの場合、デバイストークンを生成するために何も必要ありません。

 Replace YOUR_SENDER_ID in config.xml with above SENDER_ID 


     <plugin name="phonegap-plugin-push" spec="1.8.2">  
     <variable name="SENDER_ID" value="YOUR_SENDER_ID"/> 
     </plugin> 

     Add device token generation code in your main app constructor like below and replace YOUR_SENDER_ID in Push.init() method with above SENDER_ID 


     import {Component, ViewChild} from "@angular/core"; 
     import {AlertController, Nav, Platform} from "ionic-angular"; 
     import {StatusBar} from "@ionic-native/status-bar"; 
     import {SplashScreen} from "@ionic-native/splash-screen"; 
     import {Push, PushObject, PushOptions} from "@ionic-native/push"; 
     import {TabsPage} from "../pages/tabs/tabs"; 
     import {DetailsPage} from "../pages/details/details"; 

     @Component({ 
     template: '<ion-nav [root]="rootPage"></ion-nav>' 
     }) 
     export class Ionic2PushApp { 
     @ViewChild(Nav) nav: Nav; 
     rootPage: any; 

     constructor(public platform: Platform, 
        public statusBar: StatusBar, 
        public splashScreen: SplashScreen, 
        public push: Push, 
        public alertCtrl: AlertController) { 
      this.rootPage = TabsPage; 
      platform.ready().then(() => { 
      this.statusBar.styleDefault(); 
      this.splashScreen.hide(); 
      this.initPushNotification(); 
      }); 
     } 

     initPushNotification() { 
      if (!this.platform.is('cordova')) { 
      console.warn("Push notifications not initialized. Cordova is not available - Run in physical device"); 
      return; 
      } 
      const options: PushOptions = { 
      android: { 
       senderID: "YOUR_SENDER_ID" 
      }, 
      ios: { 
       alert: "true", 
       badge: false, 
       sound: "true" 
      }, 
      windows: {} 
      }; 
      const pushObject: PushObject = this.push.init(options); 

      pushObject.on('registration').subscribe((data: any) => { 
      console.log("device token ->", data.registrationId); 
      //TODO - send device token to server 
      }); 

      pushObject.on('notification').subscribe((data: any) => { 
      console.log('message', data.message); 
      //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 
        this.nav.push(DetailsPage, {message: data.message}); 
        } 
       }] 
       }); 
       confirmAlert.present(); 
      } else { 
       //if user NOT using app and push notification comes 
       //TODO: Your logic on click of push notification directly 
       this.nav.push(DetailsPage, {message: data.message}); 
       console.log("Push notification clicked"); 
      } 
      }); 

      pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error)); 
     } 
     } 
関連する問題