Phonegap 推送插件无法正常工作,在 Android 中出现未捕获的类型错误

Phonegap Push Plugin is not working giving uncaught type error in Android

我正在努力在我的混合移动应用程序构建中使用 JQuery 移动与 Cordova 包装来获取推送通知。

我正在使用 Phonegap 推送插件 (https://github.com/phonegap/phonegap-plugin-push) 来促进我的应用程序中的通知功能。当我像下面这样调用插件的 init 方法时,它给出了 init 调用下面所述的异常。

var push = PushNotification.init({ "android": {"senderID": "XXxxXXxxCXPLcIV0eay5x3mfuQKValzvDT_xxxxxx"},
     "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

Uncaught TypeError: Object function (options) {
    this._handlers = {
        'registration': [],
        'notification': [],
        'error': []
    };

    // require options parameter
    if (typeof options === 'undefined') {
        throw new ...<omitted>...t' index.js:135
registerForPushNotification index.js:135
(anonymous function) index.js:80
n.event.dispatch jquery-2.1.4.min.js:3
r.handle jquery-2.1.4.min.js:3
n.event.trigger jquery-2.1.4.min.js:3
(anonymous function) jquery-2.1.4.min.js:3
n.extend.each jquery-2.1.4.min.js:2
n.fn.n.each jquery-2.1.4.min.js:2
n.fn.extend.trigger jquery-2.1.4.min.js:3
a.Widget._trigger jquery.mobile-1.4.5.js:15451
a.Widget._createWidget jquery.mobile-1.4.5.js:15451
a.widget._createWidget jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
a.(anonymous function).(anonymous function) jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
n.extend.each jquery-2.1.4.min.js:2
n.fn.n.each jquery-2.1.4.min.js:2
a.fn.(anonymous function) jquery.mobile-1.4.5.js:15451
a.widget.transition jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
a.widget.change jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
n.extend.each jquery-2.1.4.min.js:2
n.fn.n.each jquery-2.1.4.min.js:2
a.fn.(anonymous function) jquery.mobile-1.4.5.js:15451
a.mobile.changePage jquery.mobile-1.4.5.js:15451
a.mobile.gradeA.a.extend.initializePage jquery.mobile-1.4.5.js:15451
(anonymous function) jquery.mobile-1.4.5.js:15451
j jquery-2.1.4.min.js:2
k.fireWith jquery-2.1.4.min.js:2
n.extend.ready jquery-2.1.4.min.js:2

为了调用 init 方法,我从 plugins/phonegap-plugin-push/www/push.js 中获取了文件 push.js 并放置在项目 www 文件夹中。在 index.html

中也引用了相同的内容

创建的 Android 项目的版本是,

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

感谢您的提前帮助。

我认为您正在使用 API_KEY "XXxxXXxxCXPLcIV0eay5x3mfuQKValzvDT_xxxxxx" 作为 senderID。请重新检查这个东西。

我通过在 config.xml

中添加以下内容修正了答案
<plugin name="cordova-plugin-whitelist" version="1" />

    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />

<platform name="android">
        <allow-intent href="market:*" />
</platform>

<platform name="ios">
      <allow-intent href="itms:*" />
      <allow-intent href="itms-apps:*" />
</platform>

是的,Cordova CLI 在创建项目时创建了这些。我的项目是几个月前创建的,没有这些。感谢您的帮助。

还要确保插件源文件夹不在您的项目中。