【问题标题】:Push plugin notification for apache cordova android app using phonegap-plugin-push使用 phonegap-plugin-push 为 apache cordova android 应用程序推送插件通知
【发布时间】:2017-11-17 05:12:54
【问题描述】:

我有一个基于 apache cordova 构建的 android 应用程序。我想要此应用程序的推送通知。我使用 Visual Studio 2015 IDE 构建了这个应用程序。 我已经为此应用程序安装了一些插件,例如 cordova-plugin-device-orientation、状态栏等。为了为这个应用程序启用推送通知,我安装了 phonegap-plugin-push(2.1.0 版)并为我的应用程序提供了发件人 ID我使用 Firebase 创建的。通过创建新项目,添加 android 应用程序,下载 google-services.json 文件并将其放入我的项目中。

<script>
        function setupPush() {
        //This line below throws error on simulator saying PushNotification //is not defined
            var push = PushNotification.init({
                "android": {
                    "senderID": "XXXXXXXXXX"
                },
                "ios": {
                    "sound": true,
                    "alert": true,
                    "badge": true
                },
                "windows": {}
            });
            alert('registered');
            push.on('registration', function (data) {
                alert('registration event' + data.registrationId);
                console.log("registration event: " + data.registrationId);
                var oldRegId = localStorage.getItem('registrationId');
                if (oldRegId !== data.registrationId) {
                    // Save new registration ID
                    alert('registration event' + data.registrationId)
                    localStorage.setItem('registrationId', data.registrationId);
                    // Post registrationId to your app server as the value has changed
                }
            });

            push.on('error', function (e) {
                console.log("push error = " + e.message);
            });
        }
       
        $(document).on('deviceready', function deviceIsReady() {
            console.log('Device is ready!');
            setupPush();
        });
    </script>

我找到了这个代码here

【问题讨论】:

    标签: cordova firebase visual-studio-2015 phonegap-pushplugin apache-cordova


    【解决方案1】:

    您的cordova CLI 和cordova 平台android 版本是多少? 我使用的是6.2.3 android版本,运行正常。

    请先尝试安装插件,毕竟插件安装成功比为项目安装android平台。

    【讨论】:

    • cordova-cli:6.1.1,“android”:“5.1.1”。我的 android 应用程序已经部署在 play store 上,所以 android 平台已经安装,现在无法更改。只想为我的安卓应用添加推送通知服务。
    • @Warda 您的插件版本不支持5.1.1,必须使用6.2.1或更高版本,请参考github.com/phonegap/phonegap-plugin-push/blob/master/docs/…
    • 您是否在 Visual Studio 2015 中构建了您的 apache cordova android 应用项目?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多