android - 使用 phonegap PushPlugin 避免多次 register() 调用

标签 android ios cordova phonegap-pushplugin

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/

相关文章:

ios - PhoneGap iOS - 仅当照片大于 targetheight/targetwidth 时才调整相机大小

javascript - 类型错误 : Failed to fetch - Only on Cordova application

android - 错误 :(22, 0) 找不到参数的方法实现 () [com.android.support.constraint :constraint-layout:1. 1.0-beta3]

java - 在 >=23 中膨胀类 Seekbar 时出错

android - 如何获取 RecyclerView 项目的 ViewHolder

ios - 如何解析数组中的字典,该数组位于字典中

ios - 如何在所有 View Storyboard iOS 上添加视觉效果 View 模糊?

java - 在 Android 中以编程方式添加 View

ios - 如何在 swift 中访问嵌套 JSON 对象内的值?

javascript - 在 PhoneGapp 应用程序上使用 Javascript 进行 Ajax 调用