OneSignal integration -

Hi guys,
I integrated Onesignal library into my app but when I try to init, I have an exception.

my app.component.ts

this.oneSignal.startInit(APP_ID, FIREBASE_SENDER_ID );
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
     
this.oneSignal.handleNotificationReceived().subscribe(() => {
      alert("handleNotificationReceived");
});
     
this.oneSignal.handleNotificationOpened().subscribe(() => {
      alert("handleNotificationOpened");
});
     
this.oneSignal.endInit();
"Uncaught (in promise): TypeError: object is not a function
TypeError: object is not a function
    at OneSignal.startInit (http://localhost/build/vendor.js:85108:151)
    at MyApp.enablePush (http://localhost/build/main.js:734:24)
    at http://localhost/build/main.js:761:19
    at t.invoke (http://localhost/build/polyfills.js:3:14976)
    at Object.zone._inner.zone._inner.fork.onInvoke (http://localhost/build/vendor.js:5445:33)
    at t.invoke (http://localhost/build/polyfills.js:3:14916)
    at r.run (http://localhost/build/polyfills.js:3:10143)
    at http://localhost/build/polyfills.js:3:20242
    at t.invokeTask (http://localhost/build/polyfills.js:3:15660)
    at Object.zone._inner.zone._inner.fork.onInvokeTask (http://localhost/build/vendor.js:5436:33)"

Could you please support me?

Thanks

I have always use this in my application https://documentation.onesignal.com/docs/ionic-sdk-setup

I followed the instruction but I have issue at application startup.

your code shows a different approach if you follow that link the approach is a bit different and that’s what i normally use not the ionic doc method

1 Like

The alternative approach works:

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

    window["plugins"].OneSignal
      .startInit("YOUR_APPID", "YOUR_GOOGLE_PROJECT_NUMBER_IF_ANDROID")
      .handleNotificationOpened(notificationOpenedCallback)
      .endInit();

Thanks @dotman

You are welcome @Isantaniello