【问题标题】:Phonegap Push Plugin is not working giving uncaught type error in AndroidPhonegap Push Plugin 无法在 Android 中给出未捕获的类型错误
【发布时间】:2015-10-08 06:41:11
【问题描述】:

我正在使用带有 Cordova 的 JQuery Mobile 在我的混合移动应用程序构建中获取推送通知。

我正在使用 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" />

感谢您提前提供的帮助。

【问题讨论】:

    标签: android cordova jquery-mobile cordova-plugins phonegap-pushplugin


    【解决方案1】:

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

    【讨论】:

    • 我也尝试使用项目编号 (XXXX4969XXXX) 和项目 ID (myproject-X0X0) 但结果相同
    • 您能告诉我您正在使用的 Android Support Library 版本和 Android Support Repository 版本吗?
    • 我的 Android Support Library 版本是 23.0.1,Android Support Repository 版本是 21。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 2021-12-14
      • 2019-05-19
      • 1970-01-01
      相关资源
      最近更新 更多