用于移动应用程序推送通知的PushPlugin插件似乎只允许您将回调设置为通过调用register
. 但这可能意味着应用程序每次打开时都会重新向谷歌(或任何人)注册,而谷歌的示例代码和文档表明注册应该很少发生——例如在应用程序安装或版本更改时。(而且由于它需要往返于 Google 的服务器,然后再到我自己的服务器,因此将其最小化似乎是明智的。)
有没有办法避免这种看似毫无意义的重新注册?
用于移动应用程序推送通知的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){
}
这在同一个问题上帮助了我。