2016-10-25 4 views
0

IveはIonicに基づいてハイブリッドアンドロイドアプリを作成しました。Onesignalを使用してアプリケーションに通知を送信しています。それをクリックすると、アプリのホームビューが開きます。Onesignal、Ionic App:通知をクリックしたときに特定のビューを開く

私がしようとしているのは、ユーザーが通知をクリックしたときに特定のページを開くことです。 documentationに基づいて

は、ここに私がやったことです:

マイapp.jsファイル:

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); 
    }); 

}) 

ここでは、私はここで、自分でそれをfould 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/'); 
}); 

答えて

1

です誰かがそれに苦しんでいるなら、正しいコードです:

.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); 
    }); 

}) 
関連する問題