在 iOS 中为 Firebase 使用 Cloud Functions

Posted

技术标签:

【中文标题】在 iOS 中为 Firebase 使用 Cloud Functions【英文标题】:Consuming Cloud Functions for Firebase in iOS 【发布时间】:2017-12-20 07:58:30 【问题描述】:

我使用 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 应用中使用这些功能。

谢谢

【问题讨论】:

【参考方案1】:

我已经做到了,这很容易。您需要的是在成功上传函数后点击 CLI 提供的 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 中为 Firebase 使用 Cloud Functions的主要内容,如果未能解决你的问题,请参考以下文章