【问题标题】:Consuming Cloud Functions for Firebase in iOS在 iOS 中为 Firebase 使用 Cloud Functions
【发布时间】: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 应用中使用这些功能。

谢谢

【问题讨论】:

    标签: ios firebase swift3 google-cloud-functions


    【解决方案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))
            }
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-04
      • 2018-02-04
      • 2020-02-21
      • 2018-01-14
      • 2020-03-15
      • 2021-10-25
      • 1970-01-01
      • 2017-08-02
      相关资源
      最近更新 更多