1

プッシュ通知に関するIonic 3の文書の指示に従っています。ionic 3とFirebase Cloud Messagingを使用して通知バーから特定のページを開くにはどうすればいいですか?

通知と私のアプリをバックグラウンドで送信しようとすると、「通知」イベントがトリガーされず、特定のページを通過できません。

私のアプリがフォアグラウンドになっているとき、「通知」イベントが自動的にトリガされました。

私が使用

  1. イオン3モバイルフレームワークとして

  2. FirebaseクラウドMessaginsメッセージサービス

  3. Laravelとしてlarave-FCMプラグインを使用してメッセージ

を送信します

バックエンド - プッシュメッセージのLaravelコードfirebase

$optionBuilder = new OptionsBuilder(); 
    $optionBuilder->setTimeToLive(60*20)->setContentAvailable(true); 

    $notificationBuilder = new PayloadNotificationBuilder('Hello'); 
    $notificationBuilder->setBody('Hello world')->setSound('default'); 

    $dataBuilder = new PayloadDataBuilder(); 
    $dataBuilder->addData(['custom' => 'test']); 

    $option = $optionBuilder->build(); 
    $notification = $notificationBuilder->build(); 
    $data = $dataBuilder->build(); 

    $token = "token"; 

    $downstreamResponse = FCM::sendTo($token, $option, $notification, $data); 

    $success = $downstreamResponse->numberSuccess(); 
    $failure = $downstreamResponse->numberFailure(); 
    $modification = $downstreamResponse->numberModification(); 

    echo 'Success: '.$success; 
    echo "<br>"; 
    echo 'Failure: '. $failure; 
    echo "<br>"; 
    echo 'Modification: '.$modification; 
    print_r($downstreamResponse->tokensToDelete()); 
    echo "<br>"; 
    print_r($downstreamResponse->tokensToModify()); 
    echo "<br>"; 
    print_r($downstreamResponse->tokensToRetry()); 
    echo "<br>"; 
    print_r($downstreamResponse->tokensWithError()); 

FRONTEND - app.component.ts

constructor(private translate: TranslateService, private platform: Platform, settings: Settings, private config: Config, private statusBar: StatusBar, private splashScreen: SplashScreen, public push: Push, public alertCtrl: AlertController, public storage: Storage, private backgroundMode: BackgroundMode) { 
this.initTranslate(); 
this.platform.ready().then(() => { 
    if(!this.backgroundMode.isActive) { 
    this.backgroundMode.setDefaults({silent: true}); 
    this.backgroundMode.enable(); 
    } else { 
    this.backgroundMode.disable(); 
    this.backgroundMode.setDefaults({silent: true}); 
    this.backgroundMode.enable(); 
    }  
    this.pushSetup(); 
    this.storage.get('test').then((val) => { 
    if(val == 'news'){ 
     this.nav.setRoot(TabsPage); 
    } 
    });   
}); 
} 

機能pushSetup()

pushSetup() { 
const options: PushOptions = { 
    android: { 
     senderID: '10524067XXXXX' 
    }, 
    ios: { 
     alert: 'true', 
     badge: true, 
     sound: 'false' 
    }, 
    windows: {} 
}; 

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

pushObject.on('notification').subscribe((notification: any) => { 
    if(notification.additionalData.foreground){ 
    let myAlert = this.alertCtrl.create({ 
     title: 'Push', 
     message: JSON.stringify(notification) 
    }); 
    myAlert.present(); 
    } else {   
    this.storage.set('test', 'news'); 
    } 
}); 
pushObject.on('registration').subscribe((registration: any) => { 
    console.log(registration); 
}); 
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error)); 
} 
+0

編集:追加コード – Sandy

+0

SOのような公開サイトにAPIトークンを入れないでください。 –

+0

こんにちは、ありがとうございます!私は私のトークンを隠すことを忘れました:) – Sandy

答えて

1

のマイイオンアプリコンストラクタ私は hereから答えを見つけました。

私はこのlaravelのFCMだけで設定されたタイトルで

{ 
"data" : { 
    "title": "Test Notification", 
    "body": "This offer expires at 11:30 or whatever", 
    "notId": 10, 
    "surveyID": "ewtawgreg-gragrag-rgarhthgbad" 
} 
} 

、ボディ、PayloadDataBuilderからは、addData機能上のnotIdようにFCMして送信する必要があります。

関連する問題