![](/img/trans.png)
[英]How to send notification to a specific user when the data present in firestore changes even if the app is not working in background
[英]how to send user to a specific page on clicking ngCordova local notification when app is in background
将用户发送到特定视图正在单击本地通知,但是仅当应用程序处于前台时,当我关闭应用程序并获取通知时,才将其发送到仅在
$urlRouterProvider.otherwise("/");
例如,当我们不使用WhatsApp时,我们收到一条新的消息通知,当我们单击它时,它将把我们发送到该特定的聊天页面,而不是whatsapp的主页,我该如何实现?
$ionicPlatform.ready(function () {
$scope.scheduleDelayedNotification = function () {
var now = new Date().getTime();
var _5_SecondsFromNow = new Date(now + 5 * 1000);
$cordovaLocalNotification.schedule({
id: 1,
title: 'New Notification',
text: 'Notification Message',
at: _5_SecondsFromNow
}).then(function (result) {
alert("Notification Set");
});
cordova.plugins.notification.local.on("click", function (notification, state) {
$state.go('feedback');
}, this)
};
});
var ionicApp = angular.module('starter', ['ionic', 'localNotificationModule']);
ionicApp.run(function($ionicPlatform) {
$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) {
StatusBar.styleDefault();
}
});
});
ionicApp.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'views/home.html'
})
.state('feedback', {
url: '/feedback',
templateUrl: 'views/feedback.html'
});
$urlRouterProvider.otherwise("/");
});
servicesModule.service('FirstRunScheduling', ['$rootScope', '$ionicPlatform', '$cordovaLocalNotification', '$state', function($rootScope, $ionicPlatform, $cordovaLocalNotification, $state){
var ref = new Firebase("https://feedback-system.firebaseio.com/TestTimeTable");
ref.once("value", function(data) {
var TestTimeTable = data.val().TestTimeTable;
var notificationDate;
var notificationID;
if(data.val().first_run == false)
{
$ionicPlatform.ready(function () {
for(var i in TestTimeTable)
{
notificationDate = new Date(TestTimeTable[i].year, TestTimeTable[i].month, TestTimeTable[i].day, TestTimeTable[i].hour, TestTimeTable[i].minute, 0, 0);
notificationID = i + ref.getAuth().uid.split(":")[1];
$cordovaLocalNotification.schedule({
id: notificationID,
title: 'Feedback Reminder',
text: 'Please Provide Lecture Feedback',
at: notificationDate,
autoCancel: true
}).then(function (result) {
alert("Set");
});
cordova.plugins.notification.local.on("click", function (notification, state) {
$state.go('tabs.feedback');
}, this)
}
});
}
ref.update({
first_run: true,
});
});
}]);
如果用户单击通知时正在重新启动您的应用,则
cordova.plugins.notification.local.on("click", ..)
尚未被调用,因为只有在创建新的本地通知时才调用它。
尝试在其中注册通知事件处理程序
$ionicPlatform.ready(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.