在 iOS 中使用 Firebase 的 Cloud Functions

Consuming Cloud Functions for Firebase in iOS

我已经使用 Node.js 为 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。

Function URL (helloWorld): https://us-central1-project-id.cloudfunctions.net/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))
        }
     }