parsing云 – LiveQueries – iOS客户端不起作用

我正在尝试使用Parse LiveQueries。 我使用这个parsing“Bootstrap”:“ https://github.com/parse-community/parse-server ”,
我可以看到日志: info: Create new client: 1
但我只是没有得到在查询中的更新,虽然我订阅了它。 它甚至没有达到subscription.handle的处理程序。

config.json

 { "appId": "", "masterKey": "", "appName": "", "cloud": "./cloud/main", "databaseURI": "", "publicServerURL": "", // Relevant "startLiveQueryServer": true, "liveQuery": { "classNames": ["Channel"] }, } 

AppDelegate.swift

 // Initialize Parse. let configuration = ParseClientConfiguration { $0.applicationId = self.PARSE_APP_ID $0.server = self.PARSE_SERVER } Parse.initialize(with: configuration) AppDelegate.liveQueryClient = ParseLiveQuery.Client() 

The Subscription Code (iOS Swift):

 public static func listenSubscribedChannels(handler: @escaping (_ channel: Channel) -> Void) { var subscription: Subscription<PFObject>? let query: PFQuery<PFObject> = PFQuery(className: "Channel").whereKey("subscribers", containedIn: [PFUser.current()!.objectId]) subscription = AppDelegate.liveQueryClient!.subscribe(query).handle(Event.updated) { _, channel in handler(channel) } } 

这个代码的问题是,你正在把这个代码var subscription: Subscription<PFObject>? 里面的function。

该对象必须能够保留它的内存地址以便接收事件。

例如。

 class SomeClass { var objects: [PFObject] = [] var subscription: Subscription<PFObject>? var subscriber: ParseLiveQuery.Client! let query = PFQuery(className: "Locations") func startListener() { // initialize the client subscriber = ParseLiveQuery.Client() // initialize subscriber and start subscription subscription = subscriber.subscribe(conversationQuery) // handle the event listenrs. _ = subscription?.handleEvent({ (_, event) in switch event { case .created(let object): self.objects.append(object) // do stuff default: break // do other stuff or do nothing } }) } } 

正如你从这段代码中看到的那样,我已经把variables放在了函数定义之外,以保持Subscription的内存地址。

您必须在查询之前注册您的课程,如:

 Channel.registerSubclass()