2017-10-26 20 views
0

私はPhoneGapプッシュ通知プラグインを統合しました。 Androidで通知を受け取ることができ、アプリがフォアグラウンドにあるときに特定のページを開くことができます。アプリがバックグラウンドになっている間にユーザーが通知をクリックしたときに特定のページを開きたいのですが、解決策を見つけることができません。私も下のリンクを試してみました。ここでアプリがバックグラウンドの間にIonic 3でプッシュ通知がクリックされたときに特定のページを開くにはどうすればいいですか?

https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59

私のコード

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

私も同じ問題に直面していますか?どのように修正されましたか? – Kittu

答えて

0

使用すると、このようなものである: - :

message:any; 
this.message = this.navParams.get('message'); 
- Navparamsを使用してこのメ​​ッセージが表示されます

this.nav.push(DetailsPage, {'message': data.message}); 

とDetailspage.tsコンストラクタで

このメッセージをdetailspage.html {{message}}

0

を使って表示することができます。

import {App } from "ionic-angular"; 
constructor(private app: App){...} 

です。

var nav = this.app.getActiveNav(); 
nav.push(DetailsPage, { message: data.message }); 
関連する問題