OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iOS 中为 Firebase 使用 Cloud Functions [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:23
标题: ios - 在 iOS 中为 Firebase 使用 Cloud Functions

我使用 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 Server 和控制台上,我得到了所需的值。 我不想在我的 iOS 应用程序中使用此功能。我真的不知道如何在我的 iOS 应用中使用这些功能。

谢谢



Best Answer-推荐答案


我已经做到了,这很容易。您需要的是在成功上传函数后点击 CLI 提供的 url。

Function URL (helloWorld): https://us-central1-project-id.cloudfunctions.net/helloWorld.

将 project-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))
        }
     }

关于ios - 在 iOS 中为 Firebase 使用 Cloud Functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47901274/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4