如何在 angular 中按下推送按摩时重定向 - 在 cordova 中编译的应用程序
How to redirect when press on push massage in angular-app compiled in cordova
我在这里使用这个插件:
https://github.com/phonegap-build/PushPlugin
让我可以选择重定向到 angular 应用程序中特定视图的行为在哪里?
为了举例,在ios设备中配置如下:
window.onNotificationAPN = function (event) {
if (event.alert) {
window.plugins.pushNotification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
if (event.badge) {
window.plugins.pushNotification.setApplicationIconBadgeNumber(
function (result) {
console.log('Success - ' + result);
},
function (error) {
console.log('Error - ' + error);
},
event.badge);
}
};
我猜这里的某处应该是一个代码:
如果你按下推送,现在你在这里,重定向到你喜欢的地方....
可能吗?
您可以使用$location.path()
切换/更改angular中的当前路线。只要您有权访问推送回调中的 $location
服务,通知也应该是可能的。您可以在 angular.module(...).run()
:
中注册
angular.module(...).run(function($location) {
window.onNotificationAPN = function (event) {
$location.path('/push-message-received');
};
});
我在这里使用这个插件:
https://github.com/phonegap-build/PushPlugin
让我可以选择重定向到 angular 应用程序中特定视图的行为在哪里?
为了举例,在ios设备中配置如下:
window.onNotificationAPN = function (event) {
if (event.alert) {
window.plugins.pushNotification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
if (event.badge) {
window.plugins.pushNotification.setApplicationIconBadgeNumber(
function (result) {
console.log('Success - ' + result);
},
function (error) {
console.log('Error - ' + error);
},
event.badge);
}
};
我猜这里的某处应该是一个代码:
如果你按下推送,现在你在这里,重定向到你喜欢的地方.... 可能吗?
您可以使用$location.path()
切换/更改angular中的当前路线。只要您有权访问推送回调中的 $location
服务,通知也应该是可能的。您可以在 angular.module(...).run()
:
angular.module(...).run(function($location) {
window.onNotificationAPN = function (event) {
$location.path('/push-message-received');
};
});