我有一个带有LiveQuery的解析服务器。

我可以通过日志信息Create new client: 1连接到实时查询,并且websocket.org确认连接,但是未调用任何完成块。

这是完整的代码:

self.pfclient = [[PFLiveQueryClient alloc] init];
PFQuery* query = [PFQuery queryWithClassName:@"Reqs"];
[query whereKey:@"objectId" notEqualTo:@"asdfas"];
self.subscription = [self.pfclient subscribeToQuery:query];

[self.subscription addSubscribeHandler:^(PFQuery * _Nonnull query) {
    NSLog(@"Subscribed");
}];

[self.subscription addUpdateHandler:^(PFQuery * _Nonnull query, PFObject * _Nonnull obj) {
    NSLog(@"Update");
}];

[self.subscription addErrorHandler:^(PFQuery * _Nonnull query, NSError * _Nonnull error) {
    NSLog(@"Error");
}];

最佳答案

正在运行的Swift 3.0代码:

let liveQueryClient = ParseLiveQuery.Client(server: "...", applicationId: ..., clientKey: ..)

...
var subscription: Subscription<PFObject>?

let query: PFQuery<PFObject> = PFQuery(className: "className").whereKey("objectId", equalTo: "168sdf8438")

subscription = liveQueryClient.subscribe(query).handle(Event.created) { _, message in
            print("Object created")
    }

10-08 00:19