# Push Notifications with Ionic 2

**URL:** <https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851>\
**Category:** ionic-v3\
**Created:** [September 19, 2016, 3:09pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851 "2016-09-19T15:09:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 19, 2016, 3:09pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/1 "2016-09-19T15:09:26Z")

</div>

Hi All,

I am trying to set up Push Notifications with Ionic 2.

I believe I need to set up Google Cloud Messaging (GCM). However, every tutorial I look at seems out of date, even pretty recent ones including [this Ionic 2 one](https://docs.ionic.io/services/profiles/#android-gcm-project--api-key). I think Google have changed their service to rather use Firebase.

Does anyone have reference to a tutorial that explains how to set up GCM with Ionic 2 please?

---

<div class="post-metadata">

**Author:** ![ankushagg93](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ankushagg93/32/103254_2.png) [@ankushagg93](https://forum.ionicframework.com/u/ankushagg93)\
**Post date:** [September 19, 2016, 3:49pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/2 "2016-09-19T15:49:51Z")

</div>

> [@Ionic - Push notification](https://forum.ionicframework.com/t/ionic-2-push-notification/53898/18):
>
> I’ve created a git repo for push notification demo [https://github.com/aggarwalankush/ionic2-push-base](https://github.com/aggarwalankush/ionic2-push-base) Also, server code to push notification [https://github.com/aggarwalankush/push-notification-server](https://github.com/aggarwalankush/push-notification-server)

> **[FCM setup for Android Push Notifications](https://medium.com/@ankushaggarwal/gcm-setup-for-android-push-notifications-656cfdd8adbd)**
>
> Firebase Cloud Messaging (earlier known as Google Cloud Messaging — GCM) is a mobile service developed by Google that enables third-party…

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 19, 2016, 3:59pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/3 "2016-09-19T15:59:59Z")

</div>

Thanks ankushagg93.

But, your instructions are also different to what Google (Firebase) show.

When I click `Mobile APIs`, then `Google Cloud Messaging`, I get taken to `Firebase Cloud Messaging`. This is different to your tutorial.

I think Google has recently updated their service and your tutorial is not reflecting the updates yet?

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 20, 2016, 8:26am UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/4 "2016-09-20T08:26:25Z")

</div>

Yes, google developer console changed it’s `Google Cloud Messaging API` to `Firebase Cloud Messaging`. I guess now onwards we have to use `Firebase Cloud Messaging` to send push notifications, database operation, etc.

Many of articles not updated to `Firebase Cloud Messaging` implementation.  
We hope @ankushagg93 will update his article very soon because this is a nice resource to follow as I thought.

Though it is not so much difficult process to create a project in `Firebase Cloud Messaging` for push notification.

I sharing you a link which involves the use of `Cordova fcm push plugin`. The link not involves thorough steps but helps in setup a little project.

[https://github.com/edismooth/ionic2-firebase](https://github.com/edismooth/ionic2-firebase)

or

[http://stackoverflow.com/questions/37653251/firebase-cloud-messaging-with-ionic-app](http://stackoverflow.com/questions/37653251/firebase-cloud-messaging-with-ionic-app)

And below here is the repository of `Google Firebase Cloud Messaging Cordova Push Plugin` [https://github.com/fechanique/cordova-plugin-fcm](https://github.com/fechanique/cordova-plugin-fcm).

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 20, 2016, 8:41am UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/5 "2016-09-20T08:41:03Z")

</div>

Thank you vaibsVB. I will have a look at that link.

I also found this that may be useful. It also talks about the Firebase Cloud Messaging.

> <https://stackoverflow.com/questions/39300425/setup-for-ionic-cloud-using-fcm-now-that-gcm-not-available-for-new-projects>

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 20, 2016, 2:44pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/6 "2016-09-20T14:44:46Z")

</div>

This worked for me, sending notifications from the Firebase console.

All you need is to add these 3 plugins

```
⁠⁠⁠ionic plugin add cordova-plugin-inappbrowser
ionic plugin add cordova-plugin-fcm
ionic plugin add cordova-plugin-velda-devicefeedback

```

And go to [Firebase Console](http://console.firebase.google.com/)

- Create New Project
- Add a Name to your project
- Select which platform you like (ios/android)
- Add your Package Name which is the id of your app, (you can see it in your config.xml something like id=“com.ionicframework.someTest123”) It will give you a file google-services.json
- Paste it in the platforms/android/ directory
- Then run ionic build android on your CLI
- And you can now go to Notifications Page \> New Message Make sure to select the app (id of the app) you added before sending push notification.

Now I just need to work out how to send notifications from the app.

see [https://www.npmjs.com/package/cordova-plugin-fcm](https://www.npmjs.com/package/cordova-plugin-fcm)

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 20, 2016, 2:55pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/7 "2016-09-20T14:55:30Z")

</div>

Cool. Hence suggested two different URL’s for references.  
Somehow both links shows kind of similar steps to follow.

For your scenario, the Second link work with success

> [@vaibsVB](#):
>
> [stackoverflow.com](http://stackoverflow.com)
> 
> Firebase Cloud Messaging with Ionic app
> 
> cordova, ionic-framework, push-notification, firebase
> 
> asked by
> 
> ```
> Zeeshan Hassan Memon
> 
> ```
> 
> on 08:56AM - 06 Jun 16

Happy Coding 😉

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 20, 2016, 3:23pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/8 "2016-09-20T15:23:12Z")

</div>

Hi,

I am following the plugins [instructions](https://www.npmjs.com/package/cordova-plugin-fcm), but get:

> `FCMPlugin is not defined`

How do you `import` or declare `FCMPlugin`?

Example:

In `app.ts`, I add the following:

```
  private pushNotifications(): void {

    FCMPlugin.getToken(
      function (token) {
        alert(token);
      },
      function (err) {
        console.log('error retrieving token: ' + err);
      }
    )

    FCMPlugin.onNotification(
      function (data) {
        if (data.wasTapped) {
          //Notification was received on device tray and tapped by the user. 
          alert(JSON.stringify(data));
        } else {
          //Notification was received in foreground. Maybe the user needs to be notified. 
          alert(JSON.stringify(data));
        }
      },
      function (msg) {
        console.log('onNotification callback successfully registered: ' + msg);
      },
      function (err) {
        console.log('Error registering onNotification callback: ' + err);
      }
    );

  }
}

```

Also, to add a notification, it says, do the following. But this just does not compile. It is not Typescript or Javascript. Where do you add this?

```
{
  "notification":{
    "title":"Notification title", //Any value 
    "body":"Notification body", //Any value 
    "sound":"default", //If you want notification sound 
    "click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android 
    "icon":"fcm_push_icon" //White icon Android resource 
  },
  "data":{
    "param1":"value1", //Any data to be retrieved in the notification callback 
    "param2":"value2"
  },
    "to":"/topics/topicExample", //Topic or single device 
    "priority":"high", //If not set, notification won't be delivered on completely closed iOS app 
    "restricted_package_name":"" //Optional. Set for application filtering 
}

```

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 20, 2016, 3:27pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/9 "2016-09-20T15:27:40Z")

</div>

I followed the first link i.e. [GitHub - edismooth/ionic2-firebase: [DEPRECATED] Easy example of Firebase working with Ionic 2.](https://github.com/edismooth/ionic2-firebase)

In this the code you shared, which is written inside `initializeApp()` function of `app.ts` file. And declare the `FCMPlugin` above the Component as

> ```
> declare var FCMPlugin;
> @Component({
> templateUrl: 'build/app.html'
> })
> 
> ```

Have a look at this file [https://github.com/edismooth/ionic2-firebase/blob/master/app/app.ts](https://github.com/edismooth/ionic2-firebase/blob/master/app/app.ts).  
May this helps you.

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 20, 2016, 3:31pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/10 "2016-09-20T15:31:02Z")

</div>

> [@vaibsVB](#):
>
> FCMPlugin

Thanks

Yes, that’s exactly what I do:

`declare var FCMPlugin;`

It compiles, but at run time, I get:

> `Error: Uncaught (in promise): ReferenceError: FCMPlugin is not defined`

Also, the example above doesn’t send a notification?

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 20, 2016, 3:39pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/11 "2016-09-20T15:39:20Z")

</div>

I’m also not getting much into this as of now. I just cloned the project from GitHub and applied the commands.

I’m not much sure but at least just try to add the [quote=“richardmarais, post:8, topic:63851”]  
FCMPlugin.getToken  
[/quote]  
into the `initializeApp()` function under `this.platform.ready().then(() => {`. Try this will work or not.

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [September 20, 2016, 3:42pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/12 "2016-09-20T15:42:06Z")

</div>

Nope, that doesn’t work for me either.

**app.ts**

```
declare var FCMPlugin;
...

  initializeApp() {
    this.platform.ready().then(() => {
...
    FCMPlugin.getToken(
      function (token) {
....

```

results in the following at run time:

> `Error: Uncaught (in promise): ReferenceError: FCMPlugin is not defined`

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 20, 2016, 3:46pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/13 "2016-09-20T15:46:40Z")

</div>

I’m also new to this plugin and all.

Can you just clone this project [https://github.com/edismooth/ionic2-firebase](https://github.com/edismooth/ionic2-firebase) and follow the steps suggested by them. Just check whether this works for you or not. If works then we may find what is the problem relatively.

---

<div class="post-metadata">

**Author:** ![ankushagg93](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ankushagg93/32/103254_2.png) [@ankushagg93](https://forum.ionicframework.com/u/ankushagg93)\
**Post date:** [September 20, 2016, 4:27pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/14 "2016-09-20T16:27:10Z")

</div>

Hello All,

I updated the instructions to use FCM. No need to change anything in app. Just a new way to generate API\_KEY and it’s good - just 4 steps. 👍

> [@Ionic Push Notification - Android and iOS working](https://forum.ionicframework.com/t/push-notification-android-and-ios/64004):
>
> Hello all Ionites! Push notifications are awesome. Everyone wants to implement them but implementing push notification in iOS or Android can be quite difficult without good tutorial. After asking so many forum/stackoverflow questions, I’m finally able to implement push notifications for both iOS and Android using APNS and FCM(earlier known as GCM) respectively. To help others a little, I wrote down the full steps with screenshot and full code on Github. Below are all the useful links. G…

Thanks

---

<div class="post-metadata">

**Author:** ![mridul\_ahuja](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@mridul\_ahuja](https://forum.ionicframework.com/u/mridul_ahuja)\
**Post date:** [October 13, 2016, 4:55pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/15 "2016-10-13T16:55:26Z")

</div>

I tried your solution but I’m getting the following error while building it :  
`Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.2.0`

Any idea how to fix it ?

---

<div class="post-metadata">

**Author:** ![jjacobs](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@jjacobs](https://forum.ionicframework.com/u/jjacobs)\
**Post date:** [October 13, 2016, 5:49pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/16 "2016-10-13T17:49:07Z")

</div>

In your android sdk manager make sure you have the Google Play Services installed. [http://stackoverflow.com/questions/34812616/could-not-find-any-version-that-matches-com-google-android-gmsplay-services-plu](http://stackoverflow.com/questions/34812616/could-not-find-any-version-that-matches-com-google-android-gmsplay-services-plu)

---

<div class="post-metadata">

**Author:** ![mridul\_ahuja](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@mridul\_ahuja](https://forum.ionicframework.com/u/mridul_ahuja)\
**Post date:** [October 14, 2016, 6:25am UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/17 "2016-10-14T06:25:56Z")

</div>

I currently have Google Play Services version 33 installed, and Android SDK Manager is not showing any updates for Play services.

---

<div class="post-metadata">

**Author:** ![richardmarais](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/richardmarais/32/101456_2.png) [@richardmarais](https://forum.ionicframework.com/u/richardmarais)\
**Post date:** [October 28, 2016, 2:36pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/18 "2016-10-28T14:36:50Z")

</div>

Hi mridul\_ahuja, I am also getting the same error now:

> ```
> Execution failed for task ':processDebugGoogleServices'.
> > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.2.0.
> 
> ```

It looks like something must have updated, I think in the `phonegap-plugin-push` plugin that requires an updated dependency (i.e. `com.google.android.gms to 9.2.0`.)

Have you found a solution?

> <https://stackoverflow.com/questions/40307601/updating-the-version-of-com-google-android-gms-to-9-2-0>

---

<div class="post-metadata">

**Author:** ![rabbounicha](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@rabbounicha](https://forum.ionicframework.com/u/rabbounicha)\
**Post date:** [April 2, 2017, 12:44pm UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/19 "2017-04-02T12:44:52Z")

</div>

Hi,  
I had the same issue. It worked for me by removing cordova plugin phonegap-plugin-push from the project.  
The project should not have FCM Plugin and phonegap-plugin-push at the same time. So you need to choose one plugin and send notifications with it.

---

<div class="post-metadata">

**Author:** ![vasukihn](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@vasukihn](https://forum.ionicframework.com/u/vasukihn)\
**Post date:** [April 7, 2017, 7:27am UTC](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/21 "2017-04-07T07:27:29Z")

</div>

Hi Ankush,

I was wandering if it’s possible to send push notification to desktop browsers from Ionic 2 application?

Can you please let me know any info if you have ?

Thanks in Advance!!!

[Next page](https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851.md?page=2)
