1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FCMのService Worker で受け取ったプッシュ通知を Angular 側に渡す方法

1
Last updated at Posted at 2019-10-16

この記事でやること#

Angular に導入した FCM の Sevice Worker から受け取ったプッシュ通知をコンポーネント側に渡します。

FCM 導入の細かな点については言及しません。

もし導入部分から知りたい方がいましたら、私が参考にした記事が非常にわかりやすくまとめられているので、そちらを参照してください。

Angular 側にプッシュ通知の内容を渡す#

main.ts

import { Component, OnInit } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';

@Component({
  selector: 'app-main',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss']
})
export class MainComponent implements OnInit {

 constructor(
    private messaging: AngularFireMessaging,
  ) { }

 ngOnInit() {
    
    // Angular 側へプッシュデータを渡す
    this.messaging.messages
      .subscribe( message => { console.log(message); });
  }
}

これでコンソールにはサーバ側で送信したプッシュ通知のタイトル、ボディ、データがコンソールに出力されます。

参考記事#

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?