Phonegap 推送通知类未找到错误
Posted
技术标签:
【中文标题】Phonegap 推送通知类未找到错误【英文标题】:Phonegap Push notification class not found error 【发布时间】:2015-12-31 12:45:08 【问题描述】:尝试使用 phonegap cordova 5.4.1 版本与 GSM 连接,但每次都找不到错误类,请问如何解决此问题
我想要 IOS 和 Android 的相同代码
我的设备加载事件是这样的
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,"senderID":"824841663931","ecb":"app.onNotificationGCM");
// result contains any message sent from the plugin call
successHandler: function(result)
alert('Callback Success! Result = '+result)
我的 javascript 文件是:
var PushNotification = function()
;
// Call this to register for push notifications. Content of [options]
depends on whether we are working with APNS (ios) or GCM (android)
PushNotification.prototype.register = function(successCallback, errorCallback, options)
if (errorCallback == null) errorCallback = function()
if (typeof errorCallback != "function")
console.log("PushNotification.register failure: failure parameter not a function");
return
if (typeof successCallback != "function")
console.log("PushNotification.register failure: success callback parameter must be a function");
return
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
;
// Call this to unregister for push notifications
PushNotification.prototype.unregister = function(successCallback, errorCallback, options)
if (errorCallback == null) errorCallback = function()
if (typeof errorCallback != "function")
console.log("PushNotification.unregister failure: failure parameter not a function");
return
if (typeof successCallback != "function")
console.log("PushNotification.unregister failure: success callback parameter must be a function");
return
cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", [options]);
;
// Call this if you want to show toast notification on WP8
PushNotification.prototype.showToastNotification = function (successCallback, errorCallback, options)
if (errorCallback == null) errorCallback = function ()
if (typeof errorCallback != "function")
console.log("PushNotification.register failure: failure parameter not a function");
return
cordova.exec(successCallback, errorCallback, "PushPlugin", "showToastNotification", [options]);
// Call this to set the application icon badge
PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, errorCallback, badge)
if (errorCallback == null) errorCallback = function()
if (typeof errorCallback != "function")
console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function");
return
if (typeof successCallback != "function")
console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function");
return
cordova.exec(successCallback, errorCallback, "PushPlugin", "setApplicationIconBadgeNumber", [badge: badge]);
;
//-------------------------------------------------------------------
if(!window.plugins)
window.plugins = ;
if (!window.plugins.pushNotification)
window.plugins.pushNotification = new PushNotification();
if (typeof module != 'undefined' && module.exports)
module.exports = PushNotification;
我无法下载任何插件。所以请帮助我。
告诉我如何注册到 gcm 帐户 以及如何从 gcm 发送通知 以及如何处理phonegap
请与我分享代码或解决方案
【问题讨论】:
我已解决错误当我为成功运行的项目创建 apk 时,我没有通过 phonegap 桌面应用程序检查项目的 apk 【参考方案1】:您必须将其添加为功能和插件。 更多详情可以查看Phonegap PushPlugin:https://github.com/phonegap-build/PushPlugin/issues/119
您也可以使用PhoneGap查看推送通知,如何设置推送通知:http://www.adobe.com/devnet/phonegap/articles/android-push-notifications-with-phonegap.html
【讨论】:
我在 GCM 上注册了设备,但在帖子上显示 InvalidRegistration 请帮助 服务端的注册id要和客户端生成的注册id一致。检查它们是否相同。检查此页面以了解如何获取 API 密钥。 (developers.google.com/cloud-messaging) 请检查清单文件中的权限。你可以查看官方文档,这里是链接:developers.google.com/cloud-messaging【参考方案2】:我已解决错误当我为项目成功运行创建 apk 时,我没有通过 phonegap 桌面应用程序检查项目的 apk
【讨论】:
以上是关于Phonegap 推送通知类未找到错误的主要内容,如果未能解决你的问题,请参考以下文章