使用ionic中的OneSignal插件在通知点击时路由到应用程序中的状态
Routing to a state in app on notification click using OneSignal plugin in ionic
这是我的配置文件
(function () {
'use strict';
angular
.module('app.core')
.config(['$ionicConfigProvider', '$httpProvider', '$compileProvider', function ($ionicConfigProvider, $httpProvider, $compileProvider) {
$ionicConfigProvider.tabs.position('bottom'); // other values: top
$compileProvider.debugInfoEnabled(false); // remove while debugging
$httpProvider.interceptors.push('authInterceptorService');
document.addEventListener('deviceready', function ($state) {
var notificationOpenedCallback = function (jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal.init("xxxxx-xxxxxx-xxxxxx-xxxx",
{ googleProjectNumber: "xxxxxxxxx" },
notificationOpenedCallback);
window.plugins.OneSignal.getIds(function (ids) {
var deviceId = ids;
console.log(deviceId);
localStorage.setItem('deviceId', deviceId.userId);
});
// Show an alert box if a notification comes in when the user is in your app.
window.plugins.OneSignal.enableInAppAlertNotification(true);
}, false);
}]);
})();
单击设备选项卡上堆叠的推送消息时会发生 notificationOpenedCallback。所以我想转到特定路线,而不是像现在这样打开应用程序。
在我的 notificationOpenedCallback 函数中,我希望能够路由到特定状态,例如
.state('tabs.answered', {
url: "/answered",
views: {
'tab-answered': {
templateUrl: "app/answeredfeed/answered.html",
controller: 'AnsweredCtrl',
controllerAs: 'vm'
}
},
authRequired: true
});
通常我会做
$state.go('tabs.answered');
但问题是我无法注入 $state 或 $stateprovider 以便我可以路由到 tabs.answered 。甚至可以从配置路由还是我弄错了?可以通过其他方式完成此功能吗?
将 angular.config 更改为 angular.run 并且我能够注入 $injector
因此可以做
var state = $injector.get($state);
state.go('desiredstate');
这是我的配置文件
(function () {
'use strict';
angular
.module('app.core')
.config(['$ionicConfigProvider', '$httpProvider', '$compileProvider', function ($ionicConfigProvider, $httpProvider, $compileProvider) {
$ionicConfigProvider.tabs.position('bottom'); // other values: top
$compileProvider.debugInfoEnabled(false); // remove while debugging
$httpProvider.interceptors.push('authInterceptorService');
document.addEventListener('deviceready', function ($state) {
var notificationOpenedCallback = function (jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal.init("xxxxx-xxxxxx-xxxxxx-xxxx",
{ googleProjectNumber: "xxxxxxxxx" },
notificationOpenedCallback);
window.plugins.OneSignal.getIds(function (ids) {
var deviceId = ids;
console.log(deviceId);
localStorage.setItem('deviceId', deviceId.userId);
});
// Show an alert box if a notification comes in when the user is in your app.
window.plugins.OneSignal.enableInAppAlertNotification(true);
}, false);
}]);
})();
单击设备选项卡上堆叠的推送消息时会发生 notificationOpenedCallback。所以我想转到特定路线,而不是像现在这样打开应用程序。 在我的 notificationOpenedCallback 函数中,我希望能够路由到特定状态,例如
.state('tabs.answered', {
url: "/answered",
views: {
'tab-answered': {
templateUrl: "app/answeredfeed/answered.html",
controller: 'AnsweredCtrl',
controllerAs: 'vm'
}
},
authRequired: true
});
通常我会做
$state.go('tabs.answered');
但问题是我无法注入 $state 或 $stateprovider 以便我可以路由到 tabs.answered 。甚至可以从配置路由还是我弄错了?可以通过其他方式完成此功能吗?
将 angular.config 更改为 angular.run 并且我能够注入 $injector 因此可以做
var state = $injector.get($state);
state.go('desiredstate');