0

我正在使用包含Cordova的JQuery Mobile在我的混合移动应用程序构建中获取推送通知。Phonegap Push Plugin无法在Android中提供未捕获的类型错误

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

感谢。

回答

0

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

+0

我也尝试过使用项目编号(XXXX4969XXXX)和项目编号(myproject-X0X0),但结果相同 – Joseph

+0

您能否介绍一下您正在使用的Android支持库版本和Android支持版本库? –

+0

我的Android支持库版本是23.0.1,Android支持库版本是21。 – Joseph

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> 

是,创建项目时,科尔多瓦CLI创建这些。我的项目是在几个月前创建的,没有这些。谢谢你的帮助。

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

相关问题