【问题标题】:Cordova plugin push notification not working?Cordova 插件推送通知不起作用?
【发布时间】:2017-12-02 18:59:35
【问题描述】:

我是 Cordova 的新手,我想使用 Cordova 推送通知。谁能帮我使用插件。它显示一个错误:

Error: Failed to fetch plugin https://github.com/zckrs/cordova-plugin-android-support-v4.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.

Error: cmd: Command failed with exit code 1 Error output:
npm WARN package.json helloworld@1.0.0 No repository field.
npm WARN package.json helloworld@1.0.0 No README data
npm WARN addRemoteGit Error: not found: git
npm WARN addRemoteGit at getNotFoundError (C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:14:12)
npm WARN addRemoteGit at F (C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:69:19)
npm WARN addRemoteGit at E (C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:81:29)
npm WARN addRemoteGit at C:\Program Files\nodejs\node_modules\npm\node_modules\which\which.js:90:16
npm WARN addRemoteGit at C:\Program Files\nodejs\node_modules\npm\node_modules\which\node_modules\isexe\index.js:44:5
npm WARN addRemoteGit at C:\Program Files\nodejs\node_modules\npm\node_modules\which\node_modules\isexe\windows.js:29:5

npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! code ENOGIT

npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! Please include the following file with any support request:
npm ERR! D:\ExerciseApp\node_modules\npm-debug.log

【问题讨论】:

    标签: android cordova push-notification


    【解决方案1】:

    您应该使用phonegap-plugin-push

    https://github.com/zckrs/cordova-plugin-android-support-v4.git 是一个插件,用于添加 Android Support v4 客户端库而不是推送通知。

    您可以通过在 cmd 中键入以下内容来添加 phonegap-plugin-push -

    cordova plugin add phonegap-plugin-push
    

     cordova plugin add https://github.com/phonegap/phonegap-plugin-push
    

    快速示例 -

        document.addEventListener("deviceready",onDeviceReady,false);
        function onDeviceReady(){
    
           var push = PushNotification.init({ "android": {"senderID": "91254247XXXX"}}); //add your sender ID from Firebase Cloud Messenging
    
           push.on('registration', function(data) {
               console.log(data.registrationId);
               //document.getElementById("gcm_id").innerHTML = data.registrationId;
           });
    
           push.on('notification', function(data) {
    
               alert("On Notification function!!");
                 // data.message,
                // data.title,
                // data.count,
                // data.sound,
                // data.image,
                // data.additionalData
                console.log("notification event");
                console.log(JSON.stringify(data));
                alert(JSON.stringify(data));
               //Do something 
           });
    
           push.on('error', function(e) {
               alert(e);
           });
        }
    

    注意 - 对于安卓平台,您需要将您的应用添加到Firebase Cloud Messenging,并从Firebase Console->Setting->Cloud Messenging Tab 获取您的Sender ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多