am using Ionic Framework. I have successfully registered and able to receive the notifications. But my callback function is not being called when I open a notification. It just gets called on the first init(). I have placed the code in the app.js run function() after device is ready. I searched a few forums but I could not find any solution. Below is the code:
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ’ + JSON.stringify(jsonData));
if (jsonData.additionalData && jsonData.additionalData.targetUrl) {
var state = $injector.get($state);
$state.go(jsonData.additionalData.targetUrl);
}
};
window.plugins.OneSignal.init(“MY-API_KEY”, {
googleProjectNumber: “MY-GOOGLE-PROJECT-NUMBER”,
autoRegister: true
},
notificationOpenedCallback({title: ‘test’}));
window.plugins.OneSignal.setSubscription(true);
window.plugins.OneSignal.enableNotificationsWhenActive(true);
// oneSignal.init();
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
The callback function is fired only when the app starts the first time and init is called. When I open a received notification the callback function is not fired. I am doing this just for android. Can anybody please help me out?
Below are the ionic info:
Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.0
Gulp local:
Ionic Framework Version: 1.2.4
Ionic CLI Version: 1.7.15
Ionic App Lib Version: 0.7.2
OS:
Node Version: v4.4.1
Thanks