0

I'm trying to integrate OneSignal into my Ionic v1 project. I've installed the plugin, referenced the OneSignal.js file in my index.html, and added this to my app.js:

var notificationOpenedCallback = function(jsonData) {
        console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
      };

      window.plugins.OneSignal
        .startInit("MY_APP_ID")
        .handleNotificationOpened(notificationOpenedCallback)
        .endInit();

I've also tried adding this wrapper:

if(window.plugin != undefined){
    var notificationOpenedCallback = function(jsonData) {
        console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
      };


      window.plugins.OneSignal
        .startInit("MY_APP_ID")
        .handleNotificationOpened(notificationOpenedCallback)
        .endInit();
}

The error disappears, but the push notification isn't working when I build and run on my device in iOS.

Any suggestions as to how to get OneSignal integrated into my Ionic v1 app?

pixeloftdev
  • 247
  • 2
  • 12

1 Answers1

1

you don't have to include it in index.html file use this code inside of $ionicPlatform.ready function

 var notificationOpenedCallback = function(jsonData) {
   //your code here
      };
  window.plugins.OneSignal
   .startInit("0000-000")
   .handleNotificationOpened(notificationOpenedCallback)
   .endInit();
Mohamed Inshaf
  • 327
  • 2
  • 8