Cordova 插件推送通知不起作用?
Posted
技术标签:
【中文标题】Cordova 插件推送通知不起作用?【英文标题】:Cordova plugin push notification not working? 【发布时间】: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
【问题讨论】:
【参考方案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。
【讨论】:
以上是关于Cordova 插件推送通知不起作用?的主要内容,如果未能解决你的问题,请参考以下文章
使用 cordova-plugin-fcm 插件推送通知在 iOS 生产中不起作用
FCM 推送通知在 android 中不起作用(使用 cordova-plugin-fcm 2.1.1 的 Ionic 项目)