Fireship · @fireship

Push Notifications with Ionic4 and Firebase Cloud Messaging

Uploaded September 11, 2018 · Length 10:23

Push Notifications with Ionic4 and Firebase Cloud Messaging

Summary

Set up Firebase Cloud Messaging for web push notifications in an Ionic 4 progressive web app, including subscribing users to topics and broadcasting notifications.

  • ionic 4
  • firebase cloud messaging
  • web push notifications
  • firebase cloud functions
  • ionic angular
  • firebase messaging
  • firebase functions

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    push notifications are a great way to

  3. 0:08

    keep your users engaged and you can send

  4. 0:10

    them directly through your progressive

  5. 0:11

    web app on almost all major browsers now

  6. 0:13

    in today's video you'll learn how to set

  7. 0:15

    up firebase cloud messaging for the web

  8. 0:17

    from scratch and we'll do it in an ionic

  9. 0:19

    floor progressive web app the reason I

  10. 0:21

    chose this topic is because angularfire

  11. 0:23

    2 has now become angularfire and it

  12. 0:26

    lives under the at angular namespace

  13. 0:28

    it's now a stable release with support

  14. 0:31

    for messaging and callable functions

  15. 0:32

    which you'll learn all about in this

  16. 0:34

    video if you're new like and subscribe

  17. 0:36

    and for this video I'm giving away a

  18. 0:37

    one-of-a-kind ionic fire t-shirt all you

  19. 0:40

    have to do is leave a comment below and

  20. 0:41

    I'll pick a random winner by Friday so

  21. 0:43

    today we're talking about web push

  22. 0:45

    notifications which differ from

  23. 0:47

    notifications on native installed apps

  24. 0:49

    like iOS and Android web notifications

  25. 0:52

    work in all major browsers and will feel

  26. 0:54

    just like regular push notifications on

  27. 0:56

    Android devices the big holdout is iOS

  28. 0:58

    Safari so you won't be able to send web

  29. 1:00

    notifications to iPhone users in my

  30. 1:03

    upcoming full course I'll show you how

  31. 1:04

    to set up native iOS notifications for

  32. 1:06

    an installed iPhone app but the lesson

  33. 1:09

    today strictly focuses on web

  34. 1:10

    notifications let's start by taking a

  35. 1:12

    look at what we're building and how it

  36. 1:14

    actually works under the hood the first

  37. 1:16

    thing that happens is the user grants

  38. 1:17

    permission to this app to send

  39. 1:19

    notifications when that happens firebase

  40. 1:21

    will give us a token that we can send

  41. 1:23

    messages to we could use that token to

  42. 1:25

    send a notification to an individual

  43. 1:27

    user or we can subscribe our users to a

  44. 1:29

    specific topic and broadcast

  45. 1:31

    notifications out to everybody at the

  46. 1:33

    same time there are use cases for both

  47. 1:35

    but sending topic-based notifications

  48. 1:37

    tends to be a little more complicated so

  49. 1:39

    that's what I'm going to show you how to

  50. 1:40

    setup today we'll use Kulpa functions so

  51. 1:43

    that we can trigger a cloud function

  52. 1:44

    directly from our front-end by clicking

  53. 1:46

    a button that will subscribe the user to

  54. 1:48

    a topic or unsubscribe them from a topic

  55. 1:50

    and lastly we'll set up a fire store

  56. 1:52

    cloud function that will actually

  57. 1:53

    broadcast out the messages every time a

  58. 1:55

    new document is created in the database

  59. 1:57

    to get started you'll need to have an

  60. 1:59

    existing project and you'll run firebase