我正在开发Android + Phonegap + jQuery-Mobile应用程序,我正计划使用Pusher实现推送通知。我正在使用此链接中的入门项目测试Pusher服务:http://blog.pusher.com/pusher-on-phonegap-for-android/
项目详情:
Android API目标15
Cordova 2.3.0
Pusher JavaScript Library v1.12.7
jQuery Mobile 1.3.0(最终版)
我将所有必要的.java文件和.js文件复制到我的项目中。以下是我实例化推送器连接的方法:
var CONFIG = {
PUSHER: {
APP_KEY: 'my-key'
}
};
// Connect
var pusher = new Pusher(CONFIG.PUSHER.APP_KEY);
pusher.connection.bind('state_change', connectionStateChange);
function connectionStateChange(state) {
$('#connectionStatus').html(state.current);
}
// Subscribe
var channel = pusher.subscribe('my-channel');
channel.bind('pusher:subscription_succeeded', subscriptionSucceeded);
function subscriptionSucceeded() {
$('#subscriptionStatus').html('succeeded');
}
channel.bind('my-event', handleMyEvent);
function handleMyEvent( data ) {
// window.plugins.statusBarNotification.notify("You have a notification", data.message);
$('#pusher-data').append('<pre>'+data.message+'</pre>');
}
但是一旦我运行我的项目,我就无法看到有关Pusher连接的任何日志条目,而是我在Logcat中看到类似的内容:
03-01 23:11:23.997: E/Web Console(3631): Uncaught TypeError: Object function (url) {
03-01 23:11:23.997: E/Web Console(3631): // get a new websocket object from factory (check com.strumsoft.websocket.WebSocketFactory.java)
03-01 23:11:23.997: E/Web Console(3631): this.socket = WebSocketFactory.getInstance(url);
03-01 23:11:23.997: E/Web Console(3631): // store in registry
03-01 23:11:23.997: E/Web Console(3631): if(this.socket) {
03-01 23:11:23.997: E/Web Console(3631): WebSocket.store[this.socket.getId()] = this;
03-01 23:11:23.997: E/Web Console(3631): } else {
03-01 23:11:23.997: E/Web Console(3631): throw new Error('Websocket instantiation failed! Address might be wrong.');
03-01 23:11:23.997: E/Web Console(3631): }
03-01 23:11:23.997: E/Web Console(3631): } has no method '__addTask' at file:///android_asset/www/pusher.js:1288
我现在真的被困住了。任何帮助将不胜感激。
答案 0 :(得分:1)
这里的首选解决方案是放弃使用WebSocket Java包装器,而是使用我们的HTTP回退。
Pusher JavaScript库的新测试版可通过http://js.pusher.com/2.0.0-pre/pusher.min.js
获得通过HTTPs: https://d3dy5gmtp8yhk7.cloudfront.net/2.0.0-pre/pusher.min.js
我们需要在PhoneGap中进行额外的测试,但HTTP回退应该是一个更好的解决方案。