首页 文章

Phonegap推送插件无法在Android中提供未捕获的类型错误

提问于
浏览
0

我正在使用包含Cordova的JQuery Mobile在我的混合移动应用程序构建中获得推送通知 .

我正在使用Phonegap Push Plugin(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" />

感谢您提前帮助 .

2 回答

  • 0

    我认为您正在使用 API_KEY "XXxxXXxxCXPLcIV0eay5x3mfuQKValzvDT_xxxxxx"作为 senderID . 请重新检查这件事 .

  • 0

    我通过在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在创建项目时创建了这些 . 我的项目是几个月前创建的,没有这些 . 谢谢你的帮助 .

    还要确保插件源文件夹不在项目中 .

相关问题