2017-10-11 14 views
0

通知が表示されますが、クリックするとアプリケーションが再び開きます。私が望むのは、通知をクリックすると、特定のアイテムが開きます。イオン2:クリック時に通知をプッシュ

LaravelではFirebase Cloud Messaging(FCM)用にbrozot/Laravel-FCMパッケージを使用して通知を送信し、もう一方ではIonic push notificationsを使用して通知トレイに通知を表示しています。

LaravelでsetClickAction()を使用しないと、通知をクリックするとIonicアプリケーションが開きますが、setClickAction()と設定すると何も起こりません。通知は消えるだけです。

Laravelコード

$notificationBuilder = new PayloadNotificationBuilder('my title'); 
$notificationBuilder->setBody('Hello world') 
        ->setSound('default') 
        ->setClickAction('window.doSomething'); 
$notification = $notificationBuilder->build(); 

イオン2フレームワークのサンプル

import { Component, ViewChild } from '@angular/core'; 
import { Platform, Nav, MenuController, ModalController, Events, AlertController } 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 { Storage } from '@ionic/storage'; 

import { 
    SearchPage 
} from '../pages/pages'; 

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

    rootPage: any = SearchPage; 

    constructor(
     platform: Platform, 
     statusBar: StatusBar, 
     splashScreen: SplashScreen, 
     private menu: MenuController, 
     private modalCtrl: ModalController, 
     private events: Events, 
     private push: Push, 
     private alertCtrl: AlertController, 
     private storage: Storage 
    ) { 

     platform.ready().then(() => { 
      // Okay, so the platform is ready and our plugins are available. 
      // Here you can do any higher level native things you might need. 
      statusBar.styleDefault(); 
      splashScreen.hide(); 
     }); 
     this.pushSetup(); 
    } 

    pushSetup() { 
     const options: PushOptions = { 
      android: { 
       senderID: 'xxxxxxxxxxx', 
       forceShow: true 
      }, 
      ios: { 
       senderID: 'xxxxxxxxxxx', 
       alert: 'true', 
       badge: true, 
       sound: 'true' 
      }, 
      windows: {}, 
      browser: { 
       pushServiceURL: 'http://push.api.phonegap.com/v1/push' 
      } 
     }; 

     const pushObject: PushObject = this.push.init(options); 

     pushObject.on('notification').subscribe((notification: any) => { 

     }); 

     pushObject.on('registration').subscribe((registration: any) => { 
      alert(registration.id); 
     }); 

     pushObject.on('error').subscribe(error => alert('Error with Push plugin' + error)); 

    } 

} 

(<any>window).doSomething = function() { 
    alert('doSomething called'); 
} 

私は何をしないのですか?

+0

私は同じものを実装しましたOne-Signalとfirebaseを備えたIonicの機能(どちらも無料)です。プラグインを変更したい場合は、 – Webruster

+0

のように回答してください。ありがとうございます。 – MTA

+0

私の解決策を確認してください – Webruster

答えて

0

  1. を実装するための一般的なワン信号のプッシュ通知のために実行する必要があり、これらのステップがありますがOneSignalアカウントを作成
  2. 最初のAndroidのために設定し、一方の信号で新しいアプリを追加します。 (あなたはどんなプラットフォームでもターゲットを絞ることができますが、現在はAndroidに焦点を当てています)。あなたはGoogle Server KeyとGoogle Project IDを取得する必要があります。

  3. あなたFirebaseから上記のキーが

  4. 私たちはOneSignalアカウントの設定で行われ、今Ionic2でcordova plugin

を使用してionicと統合thisの手順を使用して取得できます。

OneSignal.startInit(//google Server Key, //Google ProjectId); 
      OneSignal.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification); 
      OneSignal.setSubscription(true); 
      OneSignal.handleNotificationReceived().subscribe(() => { 
       // handle received here how you wish. 


       // this.goToReleatedPage(data.Key, data.Value); 
      }); 
      OneSignal.handleNotificationOpened().subscribe((data: any) => { 
       //console.log('MyData'+ JSON.stringify(data.additionalData)); 
       this.parseObject(data); 
      }); 

      OneSignal.endInit(); 

イオン

public parseObject(obj) { 
     for (var key in obj) { 
      this.goToReleatedPage(key, obj[key]); 
      if (obj[key] instanceof Object) { 
       this.parseObject(obj[key]); 
      } 
     } 
    } 

goToReleatedPage方法

public goToReleatedPage(Key, Value) { 
     //console.log("Pagename"+" " + Key + "ID" +" " + Value); 
     if (Key === 'xxxx') { 
      this.navCtrl.push(xxxPage, { 
       id: Value 
      }); 
     } else if (Key === 'Foo') { 
      this.navCtrl.push(foosPage, { 
       id: Value, 

      }); 
     } else if (Key === 'bar') { 
      this.navCtrl.push(barPage, { 
       id: Value 
      }); 
     } 

    } 

OneSignalからメッセージを送信する際、あなたが開く必要があるとあなたが

enter image description hereを次のようにIdを渡したいどのpageを指定する必要があります

関連する問題