如何在swift 3中使用ParseLiveQuery?

时间:2017-02-01 23:16:39

标签: parse-platform swift3 cocoapods

如何在swift 3中使用ParseLiveQuery?使用CocoaPods。

1 个答案:

答案 0 :(得分:0)

第1步:

首先安装cocoaPod。

target 'MyApp' do
  pod 'ParseLiveQuery', '~> 1.1'
end

然后在终端内运行pod install,或者从CocoaPods.app。

运行

第2步:根据文档

LiveQuery客户端界面基于订阅的概念。您可以通过在查询上调用PFQuery,从关联的实时查询服务器注册任何subscribe()的实时更新:

let myQuery = Message.query()!.where(....)
let subscription: Subscription<Message> = myQuery.subscribe()

其中Message是PFObject的注册子类。

订阅查询后,您可以处理它们上的事件,如下所示:

subscription.handleEvent { query, event in
    // Handle event
}

如果卡住,请使用Swift 3示例: https://github.com/ParsePlatform/ParseLiveQuery-iOS-OSX/tree/master/Examples/LiveQueryDemo