在 Cloud Code 中解析 LiveQuery
Parse LiveQuery in Cloud Code
我有一个 iOS 和 android 应用程序,部署在 Parse Server 中。现在,我想通过云函数使用 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
有什么想法吗?
Live Query 不适用于服务器端。
Live Query 使用网络套接字,与您的客户进行实时交互。
但是当你的应用程序关闭时,套接字也关闭了......所以你需要的是推送通知
如果您想制作一个带有解析功能的实时消息传递应用程序,您需要:
- 当您的应用程序打开时,实施解析实时查询以通过网络套接字获取新消息
- 使用推送通知,所以当您的应用程序关闭时,您会收到新消息
我有一个 iOS 和 android 应用程序,部署在 Parse Server 中。现在,我想通过云函数使用 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
有什么想法吗?
Live Query 不适用于服务器端。 Live Query 使用网络套接字,与您的客户进行实时交互。 但是当你的应用程序关闭时,套接字也关闭了......所以你需要的是推送通知
如果您想制作一个带有解析功能的实时消息传递应用程序,您需要:
- 当您的应用程序打开时,实施解析实时查询以通过网络套接字获取新消息
- 使用推送通知,所以当您的应用程序关闭时,您会收到新消息