2016-10-25 3 views
0

Ive erstellt eine Hybrid-Android-App auf Ionic basiert, Using Onesignal ich sende Benachrichtigungen an die Anwendung, funktioniert gut, die Benutzer-App erhalten die Benachrichtigung und wann Ich klicke darauf, es öffnet die App Home-Ansicht.Onesignal, Ionic App: Öffnen Sie spezifische Ansicht, wenn klicken Sie auf Benachrichtigung funktioniert nicht

Was versucht wird, ist eine bestimmte Seite zu öffnen, wenn Benutzer auf die Benachrichtigungen klicken.

auf dem documentation Basierend, hier ist das, was ich tat:

Meine app.js Datei:

angular.module('starter', ['ionic','ngCordova', 'starter.controllers', 'ui.router' ]) 

.run(function($ionicPlatform,$ionicPopup,$cordovaSplashscreen,$state) { 
    $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.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if (window.StatusBar) { 
      // org.apache.cordova.statusbar required 
      StatusBar.styleDefault(); 
     } 

     // Enable to debug issues. 
     // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4}); 

     var notificationOpenedCallback = function(result) { 
      //var data = result.notification.payload.additionalData; 

       var state = $injector.get($state); 
       state.go('#/app/post/49726'); 
     }; 

     window.plugins.OneSignal.init("********-****-****-****-***********", 
             {googleProjectNumber: "**************"}, 
             notificationOpenedCallback); 

     // Show an alert box if a notification comes in when the user is in your app. 
     window.plugins.OneSignal.enableInAppAlertNotification(true); 
    }); 

}) 

ist die stateProvider

.config(function($stateProvider, $urlRouterProvider,$ionicConfigProvider) { 
    $ionicConfigProvider.navBar.alignTitle('center'); 
    $stateProvider 
     .state('app', { 
      url: "/app", 
      abstract: true, 
      templateUrl: "templates/menu.html", 
      controller: 'AppCtrl' 
     }) 
     .state('app.home', { 
      url: "/home/", 
      views: { 
       'menuContent': { 
        templateUrl: "templates/posts.html", 
        controller: 'HomeCtrl' 
       } 
      } 
     }) 
     .state('app.posts', { 
      url: "/posts/:categoryId", 
      views: { 
       'menuContent': { 
        templateUrl: "templates/posts.html", 
        controller: 'PostsCtrl' 
       } 
      } 
     }) 
     .state('app.post', { 
      url: "/post/:postId", 
      views: { 
       'menuContent': { 
        templateUrl: "templates/post.html", 
        controller: 'PostCtrl' 
       } 
      } 
     }); 
    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/app/home/'); 
}); 

Antwort

1

ich fould es von mir, hier ist der richtige Code, wenn jemand damit zu kämpfen hat:

.run(function($ionicPlatform,$ionicPopup,$cordovaSplashscreen,$state,$injector) { 
    $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.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if (window.StatusBar) { 
      // org.apache.cordova.statusbar required 
      StatusBar.styleDefault(); 
     } 

     // Enable to debug issues. 
     // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4}); 

     var notificationOpenedCallback = function(result) { 
      $state.go('app.post', { "postId": "49726"}); 
     }; 

     window.plugins.OneSignal.init("********-****-****-****-***********", 
            {googleProjectNumber: "**************"}, 
            notificationOpenedCallback); 

     // Show an alert box if a notification comes in when the user is in your app. 
     window.plugins.OneSignal.enableInAppAlertNotification(true); 
    }); 

}) 
Verwandte Themen