【问题标题】:Phonegap Push Notification - PushNotification.init() not firingPhonegap 推送通知 - PushNotification.init() 未触发
【发布时间】:2019-03-01 17:19:37
【问题描述】:

我有一个 Phonegap 项目,它正在尝试使用 phonegap-plugin-push 接收推送通知。

我已经注册并设置了我的 Firebase 应用 (FCM) 并下载了 google-services.json 并将其放在我的根目录中(config.xml 旁边)。

当我在我的设备上使用 Phonegap 移动开发应用程序进行测试时,PushNotification.init() 会按预期触发。

** 问题:当我通过Phonegap Build(在线)编译和安装APK时,PushNotification.init()没有触发。

我的 config.xml 如下所示:

<engine name="android" spec="^7.0.0" />
<engine name="browser" spec="^5.0.4" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-plugin-network-information" spec="^2.0.1" />
<plugin name="cordova-plugin-file" spec="^6.0.1" />
<plugin name="cordova-plugin-globalization" spec="^1.11.0" />
<plugin name="phonegap-plugin-push" spec="^2.1.3">
    <variable name="FCM_VERSION" value="11.6.2" />
</plugin>
<platform name="android">
    <allow-intent href="market:*" />
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>

我的 index.js 看起来像这样:

onDeviceReady: function() {
    console.log('DEVICE READY...');

    var push = PushNotification.init({
        "android": {
            vibrate: true,
            sound: true,
            forceShow: true,
        },
        "browser": {
            pushServiceURL: 'http://push.api.phonegap.com/v1/push'
        },
        "ios": {
            alert: true,
            badge: true,
            sound: true
        }
    });

    push.on('error', function(e) {
        console.log("push error = " + e.message);
    });

    push.subscribe('example', function () {
        console.log('Subscription error:');
        console.log(e);
    });

    PushNotification.hasPermission(function (data) {
        console.log("data.isEnabled = " + data.isEnabled);
    });


    push.on('registration', function (data) {
        console.log(data.registrationId);
        console.log(data.registrationType);
    });

    push.on('notification', function (data) {
        console.log(data.message);
        console.log(data.title);
        console.log(data.count);
        console.log(data.sound);
        console.log(data.image);
        console.log(data.additionalData);
        console.log(navigator.notification);

        navigator.notification.alert(data.message, null, data.title,'Ok');
    });
}

有什么想法吗?

【问题讨论】:

    标签: android cordova phonegap


    【解决方案1】:

    在尝试启动和运行推送通知时,我没有遇到很多问题。 不完全是您要求的解决方案 - 但到目前为止 cordova-plugin-firebase 是我唯一可靠工作的插件。

    PS。 如果我没记错的话,他们的 iOS 设置指南中有一个小错误。

    单击证书名称左侧的展开箭头以显示 私钥选项

    这部分不正确,需要导出整个证书而不展开。

    【讨论】:

    • 感谢您的提示。我无法相信其中一些功能的文档记录和实现程度如何。无论如何,我解决了我的问题。在下面回答。
    【解决方案2】:

    最终,我通过完全启动一个新项目并使用来自github 的代码,设法实现了基本的推送通知功能(目前仅在 Android 上测试过)。

    在此之后,我安装了我以前的代码库,以及它们各自的插件,没有破坏任何东西。到目前为止一切顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-27
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      相关资源
      最近更新 更多