我正在开发一个 Android + Phonegap + jQuery-Mobile 应用程序,我计划使用 Pusher 来实现推送通知。我正在使用此链接中的入门项目测试 Pusher 服务:http: //blog.pusher.com/pusher-on-phonegap-for-android/
项目详情:
Android API 目标 15
科尔多瓦 2.3.0
Pusher JavaScript 库 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
在这一点上,我真的被困住了。任何帮助将不胜感激。