Manoj Rejinthala
Manoj Rejinthala

Reputation: 542

How to open a specific page when click on push notifications in Ionic?

I am new to Ionic I integrated PhoneGap push notifications plugin. I am able to receive notifications in Android and IOS. I would like to open a specific page when a user clicks on the notifications but I am not able to find any solutions. I even tried the link below.

How to open detail page when click notification in Ionic

Here is my code

ionic.Platform.ready(function() {
    var push = PushNotification.init({
        android: {
            senderID: "61426985247",
            sound: "true",
            vibrate: "true",
            forceShow: "true"
        },
        browser: {
            pushServiceURL: 'http://push.api.phonegap.com/v1/push'
        },
        ios: {
            alert: "true",
            badge: true,
            sound: 'false'
        },
        windows: {}
    });
    PushNotification.hasPermission(function(data) {});
    push.on('registration', function(data) {
        $rootScope.deviceToken = data.registrationId;
    });
    push.on('notification', function(data) {
        $state.go("tabs.createevent", {
            "eventId": "createNewEvent"
        });
        alert(data);
    });
    push.on('error', function(e) {
        alert(e.message);
    });
});

Please help me out to solve the the problem. Thanks in advance.

Upvotes: 2

Views: 3764

Answers (2)

Jayanth
Jayanth

Reputation: 1

Problem may be within your payload.

If you want to process your push message when app receives in background, you need to format the payload like below

{
    to : deviceid
    data : {
        title : "Push Notification",
        body  : "This is a push Message",
        userId: 10,
      }
}

More Info here: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#android-behaviour

Upvotes: 0

Mr.P
Mr.P

Reputation: 1440

From looking at the docs it looks like you ned to call the push.on('notification', callback) function.

Then from within the function, you can make a decision where to navigate to within the app based on the payload.

This should take place in your onDeviceReady() so that it will happen straight away. Then just route to a page like you normally would.

Upvotes: 1

Related Questions