我已经为firebase编写了一个使用节点的云功能。
exports.fetchStudents = functions.https.onRequest((request, response) => {
return admin.database().ref('Student').once('value', (snapshot) => {
var students = snapshot.val();
response.send(students)
console.log(students)
});
});
我已经通过firebase服务器部署了它,在控制台上,我得到了所需的值。我不会在iOS应用中使用此功能。我真的不知道如何在iOS应用中消耗此功能。
谢谢
我已经实现了这一点,这很容易。成功上传功能后,您需要的是点击CLI提供的URL。
函数url (Helloworld):https://us-central1-project-id.cloudfunctions.net/helledorld。
用项目ID替换项目ID。
let url = URL(string: "https://us-central1-project-id.cloudfunctions.net/fetchStudents")!
let urlReq = URLRequest(url: url)
let students = Alamofire.request(urlReq).validate().responseJSON { (response) in
switch response.result{
case .success(let value):
completion(JSON(value), nil)
case .failure(let error):
completion(nil, String(describing: error))
}
}