gpt4 book ai didi

ios - 解析 LiveQuery 订阅不接收任何事件

转载 作者:可可西里 更新时间:2023-11-01 02:16:52 30 4
gpt4 key购买 nike

我在 Amazon EC2 实例上配置了一个运行 LiveQuery 的解析服务器,在端口 9091 上,没有代理,进行了防火墙配置。它似乎工作正常,因为我们在 React 上测试并使用 http://www.websocket.org/echo.html , 提示连接成功。

但是在 iOS 上,我无法使 LiveQuery 工作,即使 handleSubscribe 似乎没问题。

我创建了一个简单的 viewController 来尝试一下:

import UIKit
import Parse
import ParseLiveQuery

class StatsViewController: UIViewController {

@IBAction func insertMessage(sender: AnyObject) {
let message = Message();
message.author = PFUser.currentUser()
message.authorName = message.author?.username
message.text = "Hello: \(NSDate())"
message.roomName = "Test";

message.saveInBackground();
}

var myQuery: PFQuery {
return (Message.query()?
.whereKey("roomName", equalTo: "2")
.orderByAscending("createdAt"))!
}

var subscription: Subscription<Message>? = nil

override func viewDidLoad() {
super.viewDidLoad()

//Registers the subclass
Message.registerSubclass();
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewDidAppear(animated: Bool) {

//1) queries for messages, working.
myQuery.findObjectsInBackground().continueWithBlock() { res in
for msg in ((res.result as? [Message]))! {
print(msg);
}
return nil
}

//2) try to subscribe and receive any information from the server
subscription = myQuery.subscribe()

subscription!.handleEvent { query, event in
// Handle event
print("any event, please?"); //no events handled after creating a new message
}

subscription!.handle(Event.Created) { query, object in
// Called whenever an object was created
print("any creation, please?"); //no events handled after creating a new message
}

subscription!.handleError { (query, err) in
print("any error, please?"); //no errors handled
}

subscription!.handleSubscribe { query in
print("subscribed")
}
}

}

我还尝试使用解析示例中的代码进行订阅,如

func subscribeToUpdates() {
subscription = liveQueryClient
.subscribe(messagesQuery)
.handle(Event.Created) { _, message in
self.printMessage(message)
}
}

订阅过程中是否有任何错误或遗漏?

谢谢!

最佳答案

尝试添加

   Message.registerSubclass();

在解析配置设置之前

关于ios - 解析 LiveQuery 订阅不接收任何事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37381388/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com