我目前正在使用ionic/ngcordova構建一個android應用程序。我正在實施推送通知。我已將推送通知實施爲在app.run(function(){..})
階段注入的服務。註冊部分工作,我收到一個包含regid
的回調。另外,當應用程序處於活動狀態時,會引發事件並收到通知。當應用程序在後臺ngCordova/Ionic推送通知
我遇到的問題是,當應用程序進入後臺時,根本沒有收到通知。我希望當應用程序沒有運行或類似的時候會發出本地通知,但絕對沒有任何反應,這很奇怪。
我在過去的兩天裏一直在尋找解決方案,但我一直無法找到任何表明它應該工作的信息。
,以下是我notificationService.js我的應用程序
app.factory('notificationService', ['$cordovaPush', function($cordovaPush){
var dataFactory = {};
//
// When the device is ready and this service has been plumbed in...
document.addEventListener("deviceready", function(){
console.log("initializing push notifications...");
_register();
}, false);
//
// Registers the device for push notifications...
var _register = function(){
var config = {};
if (device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos"){
// TODO: centralise this value as it can change...
config = {
senderID: "448168747432",
ecb: "onNotificationGCM"
};
}else {
// iOS
config = {
"badge":"true",
"sound":"true",
"alert":"true"
};
// Can add the following property to the config object to raise a callback with the information if need be...
// "ecb": "onNotificationRegisterAPN"
}
$cordovaPush.register(config).then(function(result){
//
// Typically returns "ok" for android and devicetoken for iOS
console.log(result);
});
};
window.onNotificationGCM = function(result){
console.log(result);
/*
I get called when the app is in the foreground, but nothing happens when the app is in the background.
*/
};
dataFactory.register = _register;
return dataFactory;
}]);
裏面如果有幫助,我通過.NET應用程序中使用PushSharp以投遞通知。任何幫助將不勝感激。
更新:我使用下面的框架/庫:
- 離子框架1.2.14-beta6
- 科爾多瓦4.2.0
- PushPlugin