在iOS中使用Firebase的云功能
我已经使用Node为Firebase编写了一个云函数在iOS中使用Firebase的云功能,ios,firebase,swift3,google-cloud-functions,Ios,Firebase,Swift3,Google Cloud Functions,我已经使用Node为Firebase编写了一个云函数 exports.fetchStudents = functions.https.onRequest((request, response) => { return admin.database().ref('Student').once('value', (snapshot) => { var students = snapshot.val(); response.send(students
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): 用项目的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))
}
}