我创建了https云函数,并在iOS应用程序中向其发出请求。云函数已被调用,因为我可以看到日志,但我无法从我从iOS应用程序发送的请求中获取参数。我尝试了几个不同的选项,但它们没有帮助我,请告诉我如何达到结果?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
module.exports = functions.https.onRequest((req, res) => {
console.log("getChatGroupConversationAvatars start", req.params);
const requestDict = req.params;
console.log("requestDict", requestDict);
const queryFormat = req.query.format;
console.log("queryFormat", queryFormat);
const conversationID = requestDict["conversationID"];
const currentUserID = requestDict["currentUserID"];
console.log("conversationID", conversationID, "currentUserID", currentUserID);
return console.log("getChatGroupConversationAvatars");
});
iOS应用程式代码
class ChatAvatarsManager {
func getChatGroupConversationAvatars(_ conversationID: String) {
DispatchQueue.main.async {
guard let currentUserID = RealmManager().getCurrentUser()?.id else { return }
DispatchQueue.global(qos: .background).async {
let path = "https://us-central1-exampleapp.cloudfunctions.net/getChatGroupConversationAvatars"
guard let url = URL(string: path) else { return }
let parameters = ["conversationID" : conversationID, "currentUserID" : currentUserID]
AlamofireExampleManager.shared.request(url, method: .get, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
switch response.result {
case .success:
debugPrint("getChatGroupConversationAvatars success")
case .failure(let error):
if error._code == NSURLErrorTimedOut {
//timeout here
debugPrint("getChatGroupConversationAvatars timeOut")
}
debugPrint("getChatGroupConversationAvatars \(error)")
}
}
}
}
}
}
struct AlamofireExampleManager {
static let shared: SessionManager = {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10
let sessionManager = Alamofire.SessionManager(configuration: configuration)
return sessionManager
}()
比如在日志中我得到了这个结果
conversationID undefined currentUserID undefined
我也试过了
module.exports = functions.https.onRequest((req, res) => {
const conversationID = req.params.conversationID;
const currentUserID = req.params.currentUserID;
console.log("conversationID", conversationID, "currentUserID", currentUserID);
return console.log("getChatGroupConversationAvatars");
});