【发布时间】:2016-10-25 17:26:07
【问题描述】:
我创建了一个基于 Ionic 的混合 android 应用程序,我使用 Onesignal 向应用程序发送通知,它运行良好,用户应用程序收到通知,当我点击它时,它会打开应用程序主页视图。
我想要做的是当用户点击通知时打开一个特定的页面。
基于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);
});
})
这里是状态提供者
.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/');
});
【问题讨论】:
标签: cordova ionic-framework push-notification onesignal