PushPlugin用于移动应用程序推送通知的插件似乎只允许您设置要通过调用 register
来使用的回调。但这可能意味着该应用程序每次打开时都会向谷歌(或任何人)重新注册,而谷歌的示例代码和文档表明注册应该很少发生——例如,在应用程序安装或版本更改时。 (因为它需要往返 Google 的服务器然后再到我自己的服务器,所以无论如何尽量减少它似乎是明智的。)
有没有办法避免这种看似毫无意义的重新注册?
最佳答案
请看这个解决方案 https://github.com/phonegap-build/PushPlugin/pull/287/files
只需对插件文件进行一些修改,您就会得到结果。
修改后... 在您只需要收听通知而无需注册的 html 页面中,您必须调用它(在设备准备好后):
var pushNotification;
pushNotification = window.plugins.pushNotification;
pushNotification.setupCallbacks(
SuccessHandler,
errorHandler,
{
"senderID":"yoursenderID",
"ecb":"onNotification"
});
function SuccessHandler(result){
console.log("Active On Notification without register ==================================");
console.log(result);
}
function errorHandler(error){
}
这在同一问题上帮助了我。
关于android - 使用 phonegap PushPlugin 避免多次 register() 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25877492/