【发布时间】:2026-02-18 21:35:01
【问题描述】:
我想使用 Firebase Cloud Functions,所以我从简单的“Hello world”示例开始作为后端部分,并从直接从应用调用函数的 iOS 示例开始。
云功能:
export const helloWorld = functions.https.onRequest((request, response) => {
response.send('{"response":"Hello world"}') //option3
response.send('Hello world');//option2
response.send("Hello world");//option1 as in docs
});
我尝试了 3 种不同的响应选项。控制台说它有效。如果在浏览器中打开函数 url,它会打印“Hello world”。
iOS部分:
[[_functions HTTPSCallableWithName:@"helloWorld"] callWithObject:nil
completion:^(FIRHTTPSCallableResult * _Nullable result, NSError * _Nullable error) {
if (error) {
if (error.domain == FIRFunctionsErrorDomain) {
NSLog(@"domain code %ld@, details %@", error.code, error.userInfo[FIRFunctionsErrorDetailsKey] );
}
NSLog(@"code %ld, message %@, details %@", error.code,error.localizedDescription, error.userInfo[FIRFunctionsErrorDetailsKey]);
return;
}
NSLog(@"result: %@", result.data);
}];
它返回(在 3 个选项中的每一个中):代码 3840,消息无法读取数据,因为它的格式不正确。,详细信息(空)
如果响应格式一直由 Firebase 处理,我该怎么办?
【问题讨论】:
标签: ios firebase google-cloud-functions