在Cordova Android上无法让pushwoosh接收通知

时间:2019-01-17 11:44:33

标签: android cordova firebase-cloud-messaging pushwoosh

出于某种原因,我不理解,我没有在Android设备上收到PN。

我确实在console.firebase.google.com中配置了GCM。

我确实将生成的google-services.json文件放在了cordova项目的platform/android文件夹中。

我当然安装了cordova pushwoosh-phonegap-plugin插件。

我添加了代码,并在应用程序的引导程序中调用了此代码:

function initPushwoosh(store) {
    var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");

    // Should be called before pushwoosh.onDeviceReady
    document.addEventListener('push-notification', function(event) {
        console.log('RECEIVED PN: ',event);
    });

    // Initialize Pushwoosh. This will trigger all pending push notifications on start.
    pushwoosh.onDeviceReady({
        appid: "...",
        projectid: "..."
    });

    if (myApp.pnToken == null) {
        pushwoosh.registerDevice(
            function(status) {
                var pushToken = status.pushToken;
                console.log('received token',pushToken);
            },
            function(status) {
                console.error(status);
            }
        );
    }
    else {
        pushwoosh.getPushwooshHWID(function(pwid){console.log('PUSHWOOSH ID: ',pwid);});
    }
}

在运行时,我看到我的应用程序已成功订阅PUSHWOOSH(我收到一个pw令牌并具有一个pw客户端ID),并且在Pushwoosh管理界面中看到了我在Android“用户”中唯一的测试Android设备。 / p>

但是,当我从PW管理界面发送示例通知时,永远不会触发“推送通知”事件。

以下是有关部分logcat的更多信息:

    01-17 11:26:57.144 9254-9653/my.app D/Pushwoosh: [CordovaPlugin] Plugin Method Called: onDeviceReady
    01-17 11:26:57.145 9254-9653/my.app I/Pushwoosh: [NotificationManager] App ID: XXXXX-XXXXX
    01-17 11:26:57.147 9254-9653/my.app I/Pushwoosh: [NotificationManager] Sender ID: XXXXXXXXXX
    01-17 11:26:57.149 9254-9254/my.app D/Pushwoosh: onAppReady
        sendAppOpenEndTagMigrate
    01-17 11:26:57.154 9254-9653/my.app D/Pushwoosh: [CordovaPlugin] Plugin Method Called: getPushwooshHWID
    01-17 11:26:57.160 9254-9254/my.app D/Pushwoosh: [[BusinessCase]] trigger welcome-inapp
        [BusinessCase] welcome-inapp condition not satisfied
        [[BusinessCase]] trigger app-update-message
    01-17 11:26:57.161 9254-9254/my.app D/Pushwoosh: [BusinessCase] app-update-message condition not satisfied
    01-17 11:26:57.172 9254-9254/my.app D/Pushwoosh: [JobServiceEngineImpl] onStartJob: android.app.job.JobParameters@344323
    01-17 11:26:57.183 9254-18165/my.app D/Pushwoosh: [RequestManager] Try To send: applicationOpen; baseUrl: https://DB224-ABAD6.api.pushwoosh.com/json/1.3/

    01-17 11:26:57.588 9254-18165/my.app I/Pushwoosh: [RequestManager] 
        x
        |     Pushwoosh request:
        | Url: https://xxxxx.api.pushwoosh.com/json/1.3/applicationOpen
        | Payload: {"request":{"application":"XXXXXX","hwid":"xxxxxx","v":"5.11.0","device_type":3,"userId":"xxxxx","device_name":"Phone","language":"fr","timezone":3600,"android_package":"my.app","jailbroken":1,"device_model":"Samsung SM-G950F","os_version":"8.0.0","app_version":"1.3.4","notificationTypes":6}}
        | Response: {"status_code":200,"status_message":"OK","response":{"required_inapps":[]}}
        x

怎么了?

几个问题: -platform/androidgoogle-services.json文件的正确位置吗? -其他问题:cordova插件是否需要those steps中的任何一个? -Firebase SDK配置的最后一步(显然是可选的)没有结束:

enter image description here

有什么后果吗?

1 个答案:

答案 0 :(得分:0)

好的,我有2个问题: 首先,我应该使用“旧”类型的FCM服务器密钥,而我应该使用新的。 其次,我希望通过监听'push-notification'事件在应用程序处于前台时收到推送通知。我本来应该听'receive-push'事件的...这样做解决了我在实际接收通知(以及我的js代码中宝贵的userdata)时遇到的麻烦。