我正在使用Firebase作为后端来构建iOS应用,并且需要使用Firebase Callable Cloud Functions。我已经按照文档设置了所有功能,并且在从浏览器或curl启动时会启动并正常运行,但无法从我的应用中启动它们。
我仅使用功能设置了一个测试应用程序,但我也无法从iOS应用程序中启动该应用程序。甚至没有基本的问候世界。什么都没有解决。
已完成以下所有操作:
Firebase端:
iOS端:
我什么也没得到...按钮上的打印语句有效,但是该功能不会触发,并且没有任何内容记录到Firebase日志中。
我在这里想念什么或做错什么了?
使用Firebase的新实例尝试了新项目。 直接从Firebase文档上的示例复制代码,并逐步遵循所有内容
防火墙代码
const functions = require('firebase-functions');
const admin = require('firebase-admin')
exports.helloWorld = functions.https.onCall((data, context) => {
const text = data.text;
console.log("Text: " + text);
const uid = context.uid;
console.log("UID: " + uid);
const name = context.name;
console.log("Name: " + name);
console.log('Hello world fucking worked baby!');
return {
message: text
}
});
SWIFT CODE
import UIKit
import FirebaseFunctions
class ViewController: UIViewController {
lazy var functions = Functions.functions()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func fireFunction(_ sender: Any) {
print("Button Fire")
let data = ["text": "hello!"]
functions.httpsCallable("helloWorld").call(data) { (result, error) in
print("Function returned")
if let err = error {
print(err)
}
if let res = result {
print(res)
}
}
}
}
答案 0 :(得分:0)
如果从浏览器中调用Google Cloud Function
似乎工作正常。您还可以查看云功能的日志。只需转到Cloud Functions
页,然后单击您的函数。单击VIEW LOGS
按钮,然后尝试再次调用该URL,如果Swift调用它的方式有误,则会将该URL记录在其中。
我与iOS Swift的合作不是很多,但是由于您试图通过Internet调用该函数,因此我认为您可能需要授予该应用访问Internet的权限。调用似乎从未在Cloud Function中启动,这就是为什么未触发该调用的原因。
我假设Cloud Function是HTTP触发的。因此,作为一种解决方法,您可以调用该函数以从App发起HTTP请求。同样,除非您确保您的应用程序具有使用互联网的权限,否则这将无法工作。