Push Notifications with OneSignal for your Ionic app


Some time ago I’ve post the article about sending notifications to your Ionic app using Ruby on Rails. That article is still actual, however we have another (easier) way to send the push notifications. This way name is ‘use push notifications service’.

There are a couple of existing push notifications services, such as PushWoosh, OneSignal, Ionic pushes, etc. I want to tell you about one of them – it’s OneSignal. The main advantage of this service is its price – OneSignal is completely free! So let’s discover how to setup OneSignal Push notifications with your Ionic app!

First of all, install OneSignal SDK:

Than please use OneSignal documentation to setup your push notifications credentials:
Generate iOS push certificate
Generate Google server API key

Now it’s time to setup Ionic part of our push notifications project (app.component.ts):

That’s it! Now you can change YOURONESIGNALAPPID to correct value and start receive notifications (you can send them using the OneSignal control panel).

The only thing left is to understand how to send push notification from your backend. It’s really easy (PHP example):

This code will send a message to all devices in your app. Please refer to OneSignal documentation to understand how to customize this solution and please don’t forget to change $ONESIGNAL_APP_ID and $REST_API_KEY to proper values (can be obtained on ‘AppSettings’ page -> ‘Keys & IDs’ tab of OneSignal dashboard).

My restaurant delivery Ionic app starter using OneSignal push notifications service. To setup this push notifications, you have only to setup your OneSignal account and save your OneSignal App ID and REST API key under ‘Settings’ menu – no coding is required.

Leave a Reply

Your email address will not be published. Required fields are marked *