我有一个iOS和android应用程序,部署在一个解析服务器中。现在,我想使用LiveQuery SDK,从一个云函数!
这是我的云代码:
Parse.Cloud.define("subscribeQueryFunction", function(request, response) {
var query = new Parse.Query("Message");
var subscription = query.subscribe();
subscription.on("create", (object) => {
response.success(object);
});
});
以及我的Swift代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
PFCloud.callFunction(inBackground: "subscribeQueryFunction", withParameters: nil) { (res: Any?, e: Error?) in
print(res)
print(e)
}
}
问题是,客户没有得到回应!不过,我查看了日志,订阅似乎已经建立:
2017-05-14T16:49:12.442Z - Ran cloud function subscribeQueryFunction for user D7FP3cts5p with: Input: {} Result: {"text":"hey","createdAt":"2017-05-14T16:49:12.412Z","updatedAt":"2017-05-14T16:49:12.412Z","objectId":"DXCiumOTal","__type":"Object","className":"Message"}2017-05-14T16:49:11.101Z - Ran cloud function subscribeQueryFunction for user D7FP3cts5p with: Input: {} Result: {"text":"hey","createdAt":"2017-05-14T16:49:11.044Z","updatedAt":"2017-05-14T16:49:11.044Z","objectId":"qkXS6csCKJ","__type":"Object","className":"Message"}2017-05-14T16:49:09.099Z - Ran cloud function subscribeQueryFunction for user D7FP3cts5p with: Input: {} Result: {"text":"hey","createdAt":"2017-05-14T16:49:09.080Z","updatedAt":"2017-05-14T16:49:09.080Z","objectId":"ydnrDHO9AP","__type":"Object","className":"Message"}2017-05-14T16:47:45.183Z - Create new client: 0
有什么想法吗?
最佳答案
实时查询不用于服务器端。
实时查询使用web套接字,与客户机实时交互。
但当你的应用程序关闭时,插座也关闭了。。。所以你需要的是推送通知
如果您想使用parse制作一个实时消息传递应用程序,您需要:
实现Parse Live查询以在应用程序打开时使用web套接字获取新消息
使用推送通知,因此当你的应用程序关闭时,你会收到新消息
关于ios - 在Cloud Code中解析LiveQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43966542/