【发布时间】:2020-11-05 13:53:10
【问题描述】:
关于 firebase 函数的文档不足。httpsCallable("findItems").call() 用法。我已经在 firebase 上部署了函数:
exports.findItems = functions.https.onCall((data, context) => {
// Grab the long parameter.
functions.logger.log(data.long, typeof data.long);
functions.logger.log(data.lat, typeof data.lat);
const long = parseFloat(data.long);
const lat = parseFloat(data.lat);
functions.logger.log(long, typeof long);
functions.logger.log(lat, typeof lat);
//...
}
我使用 functions.httpsCallable("findItems").call() 快速发出请求,但日志总是说没有正确的参数:
functions.httpsCallable("findItems").call(["lat": userLocation?.latitude, "long": userLocation?.longitude]) { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
}
// ...
print(error)
return
}
print(result?.data)
do{
let json = try JSONDecoder().decode([ItemLocation].self, from:result?.data as! Data)
print(json)
}catch{
}
// if let text = (result?.data as? [String: Any])?
//(result?.data as? [String: Any])?["text"] as? String {
//self.resultField.text = text
}
您可以从https://firebase.google.com/docs/functions/callable找到官方文档
-----更新---------
我已经通过调试尝试了所有方法,传递的参数始终未定义,但我遵循官方文档中的每一步。 我做了更改并使用了 onCall 但它仍然不起作用?
【问题讨论】:
标签: swift firebase google-cloud-functions