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 (‘app.post’, {
‘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
},
NotificationOpenedCallback);
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('app.post', {'postId': + jsonData.additionalData.myKey});
}
}
})
// the rest of your code
})
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