2

所以我有一個使用C2DM消息的應用程序。當它在我的電腦上託管時,它可以在本地服務器模式下完美工作。但是,當我將應用程序部署到應用程序引擎時,它不再有效!我一直在拉我的頭髮,不知道爲什麼這是。C2DM消息傳遞在本地服務器上工作,但不在生產中(Google App Engine)

我已經嘗試過使用1.5.2和1.5.3 App Engine SDK並針對Eclipse上的2.3和2.4 GWT插件進行構建。這些似乎沒有工作。我可以很好地註冊手機,但沒有C2DM消息似乎要到達手機。

回答

2

好的,所以我挖掘了一下,發現Google提供的代碼存在一個錯誤。在本地服務器上,它將註冊數據用戶名全部小寫([email protected] - > [email protected])。在生產服務器上,它不使用全部小寫來存儲電子郵件。以下方法查詢數據存儲,以全部小寫形式提供電子郵件作爲參數。

解決方案:在註冊時將電子郵件保存到數據存儲區時,註釋掉指定的行或找到使用全部小寫字母的方法。

/** 
* Helper function - will query all registrations for a user. 
*/ 
@SuppressWarnings("unchecked") 
public static List<DeviceInfo> getDeviceInfoForUser(String user) { 
    PersistenceManager pm = PMF.get().getPersistenceManager(); 
    try { 
     // Canonicalize user name 
-----> user = user.toLowerCase(Locale.ENGLISH); 
     Query query = pm.newQuery(DeviceInfo.class); 
     query.setFilter("key >= '" + 
       user + "' && key < '" + user + "$'"); 
     List<DeviceInfo> qresult = (List<DeviceInfo>) query.execute(); 
     // Copy to array - we need to close the query 
     List<DeviceInfo> result = new ArrayList<DeviceInfo>(); 
     for (DeviceInfo di : qresult) { 
      result.add(di); 
     } 
     query.closeAll(); 
     log.info("Return " + result.size() + " devices for user " + user); 
     return result; 
    } finally { 
     pm.close(); 
    } 
} 
0

加上user = user.toLowerCase(Locale.ENGLISH);之前的查詢,肯定會有效。

相關問題