Probleme with onesignal push notification

Hi I am new on this forum, so I have a problem in onesignal, I do not receive notifications and and how I have to go on the post link when I click on the notification, here is my code

In apps.js
// Add additional data (data field in the REST API) when you send your notification with yourUrlKey equal to the url you want to navigate to.
Var notificationOpenedCallback = function (jsonData) {
If (jsonData.additionalData) {
If (jsonData.additionalData.postid)
// alert (“Notification received: \ n” + jsonData.additionalData.postid);
$ State.go (‘’, {
‘PostId’: + jsonData.additionalData.postid
If (jsonData.additionalData) {
If (jsonData.additionalData.actionSelected == “id1”)
$ State.go (‘app_settings’);
If (jsonData.additionalData) {
If (jsonData.additionalData.actionSelected == “id2” && jsonData.additionalData.postid && jsonData.additionalData.sharelink)
Window.plugins.socialsharing.share (‘Check this post here:’, null, null, jsonData.additionalData.sharelink);

    // Update with your OneSignal AppId and googleProjectNumber before running.
    Window.plugins.OneSignal.init (ONESIGNAL_APP_ID, {
            GoogleProjectNumber: GOOGLE_PROJECT_NUMBER

Window.plugins.OneSignal.enableNotificationsWhenActive (true);

In config.xml

// Replace with your Google Project Number
.constant (‘GOOGLE_PROJECT_NUMBER’, ‘287321264638’)

// Replace with your OneSignal AppId
.constant (‘ONESIGNAL_APP_ID’, ‘cf8bf6ec-8303-44b8-a66b-7c21d75bcd8e’)

Thnak you to help me

Can you try

.handleNotificationOpened( notificationOpenedCallback )

This works for me.

thanks you, can u write me all the code

lol. I don’t have a test app which i can share. But, you can refer here

I have already successfully received the notification but when I click on the notification I will not rederige on the exact post but it just opens my application on the home page I want the notification opens in the post because I Connects my application with wordpress, I have to receive notifications when I add a post and thank you very much

You have to put the callback under IonicPlatform.ready
Should look like this:

.run(function($ionicPlatform, $state) {
 $ionicPlatform.ready(function() {
var notificationOpenedCallback = function(jsonData) {
  if (jsonData.additionalData) {
    if (jsonData.additionalData.myappurl)
      $state.go('', {'postId': + jsonData.additionalData.myKey});
 // the rest of your code

thanks, but not work for me

Any errors in Console?

this is my code

Running it in browser wont work.
First, run it with a device or emulator. The browser can’t understand Cordova Plugins.

If you are doing that then OneSignal Plugin has not been installed properly.
Refer Here: Follow the steps for Ionic

1 Like

Thanks i solved this problem i have to build the apk from phonegap build

Thanks, I’ve tried this code, but the notification still open in the browser ?!

Hi :slight_smile: i tried the same but can not get the subscribe user in onesignal …can u please please please send the code that works in ionic v1 :slight_smile:

please refer my repo :

did you manage to follow the instruction in onesignal website? there are several steps for you to create an app_id which includes the gcm_key(google key) for yuou to generate and used