Parse Live Query 設定

伺服器端設定變更

{
  "appId": 'my_app_id',
  "masterKey": 'my_master_key',
  // ...
  "liveQuery": {
    "classNames": ['Test', 'TestAgain']  // Live Query 要支援的 Class
  }
}
  • 除此之外,還需要把掛載 Parse 的 http(s)Server 拿來創建一個 Live Query Server

// 原本 Express
let httpServer = require('http').createServer(app);
httpServer.listen(port);

// 新增 Live Query Server
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

LiveQuery 服務器的 ws protocol 會沿用 http(s)Server 監聽的主機名和端口。例如,如果 http(s)Sever 正在偵聽 localhost:8080,則 LiveQuery 服務器的 ws protocol 為 ws://localhost:8080/

Android Client 設定

  • 在 gradle 設定檔案中新增 dependency

  • 針對特定的 Query 進行 Subscribe

  • 監聽所有事件

  • 監聽特定事件

iOS Client 設定

  • 在 pod 設定檔案中新增 dependency

  • 針對特定的 Query 進行 Subscribe

  • 監聽所有事件

  • 監聽特定事件

Last updated