简体   繁体   English

在Cloud Code中解析LiveQuery

[英]Parse LiveQuery in Cloud Code

I have an iOS and android application, deployed in a Parse Server. 我有一个iOS和android应用程序,已部署在Parse Server中。 Now, I want to use the LiveQuery SDK, from a cloud function! 现在,我想通过云功能使用LiveQuery SDK!

Here's my cloud code: 这是我的云代码:

Parse.Cloud.define("subscribeQueryFunction", function(request, response) {
    var query = new Parse.Query("Message");
    var subscription = query.subscribe();

    subscription.on("create", (object) => {
        response.success(object);
    });
});

And my Swift code: 而我的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)
    }
}

The thing is, that the client doesn't get a response! 问题是,客户没有得到回应! Although, I checked the logs and the subscription seems to be established: 虽然,我检查了日志,但订阅似乎已建立:

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

Any ideas? 有任何想法吗?

Live Query is not made to use on the server side. 实时查询不能在服务器端使用。 Live Query use web sockets, to interact in real time with your client. Live Query使用Web套接字与您的客户端实时交互。 But when you app is close the socket is close too ... So want you need is push notifications 但是当您关闭应用程序时,套接字也关闭了...所以您需要的是推送通知

If you want to make a real time messaging application with parse your need to: 如果您想通过解析制作一个实时消息应用程序,则需要:

  • Implement Parse Live Query to get new messages with the web sockets when you app is open 当您打开应用程序时,实施Parse Live Query以通过Web套接字获取新消息
  • Use push notifications, so when you app is close, you get the new messages 使用推送通知,因此当您的应用关闭时,您会收到新消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM