2013-03-01 131 views
0

我正在開發Android + Phonegap + jQuery-Mobile應用程序,我正計劃使用Pusher實現推送通知。 http://blog.pusher.com/pusher-on-phonegap-for-android/PhoneGap無法正常工作

項目的詳細信息:使用入門指南項目從這個鏈接我測試的推服務

的Android API目標15

科爾多瓦2.3.0

推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>'); 
      } 

但是,一旦我跑我的項目,我無法看到有關推杆連接任何日誌條目,而是我看到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 

我真的很堅持在這一點上。任何幫助將不勝感激。

回答

1

這裏首選的解決方案是放棄使用WebSocket Java包裝,而使用我們的HTTP後備。

推動JavaScript庫的新的beta版可通過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回落應該是一個更好的解決方案。

+0

是否有任何消息可用?我仍然無法在Android上使用我的Phonegap/Cordova 3.0應用程序中的Pusher(適用於iOS)。 – mikrobi 2013-09-06 09:23:22

+0

@mikrobi所以,如果你使用https://github.com/pusher/pusher-phonegap-android它不能連接? – leggetter 2013-09-21 20:50:33