Kelvin
Kelvin

Reputation: 2288

Ionic App Onesignal Push Notification not able to redirect to specific page

I am trying to redirect to a specific job page when there's a new applicant.

Here's the code:

app.run(function($ionicPlatform, $location) {
  $ionicPlatform.ready(function() {
    if (ionic.Platform.isWebView()) {    
      window.plugins.OneSignal
      .startInit("xxxxxxxxxxxxxx", "xxxxxxxxxxxx")
      .handleNotificationReceived(function(jsonData) {
        console.log("/app/upcoming/" + jsonData.payload.additionalData.url);
        $location.path("/app/upcoming/" + jsonData.payload.additionalData.url);
      })
      .endInit();
    }

The console shows the correct address but it does not redirect or have any errors.

Upvotes: 0

Views: 768

Answers (1)

jkasten
jkasten

Reputation: 3948

For Ionic you will need to use $state.go to redirect the user to a different page in your app.

var notificationOpenedCallback = function(result) {
  var data = result.notification.payload.additionalData;
  if (data && data.targetUrl) {
    var state = $injector.get($state);
    state.go(data.targetUrl);
  }
};

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

Upvotes: 1

Related Questions