在iOS中使用Firebase的云功能 [英] Consuming Cloud Functions for Firebase in iOS

查看:60
本文介绍了在iOS中使用Firebase的云功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Node为Firebase编写了一个云功能.

I've written a cloud function for Firebase using Node.

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应用程序中使用此功能.

I've deployed it over Firebase Server and at console, I'm getting desired values. I wan't to use this function in my iOS app. I really don't know how to consume this functions in my iOS app.

谢谢

推荐答案

我已经做到了,这很容易.成功上传功能后,您需要点击CLI上提供的网址.

I've achieved this, it's quite easy. What you need is to hit the url provided at CLI after successful upload of function.

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

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

用您的项目ID替换项目ID.

replace project-id by your project's 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的云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆