首页 > 解决方案 > Swift Firebase 函数错误:NSCocoaErrorDomain

问题描述

当我尝试从 Swift 运行 Firebase 函数时,我收到一条错误消息:

错误域 = NSCocoaErrorDomain 代码 = 3840 “JSON 文本没有以数组或对象开头,并且允许未设置片段的选项。” UserInfo={NSDebugDescription=JSON 文本没有以数组或对象开头,并且允许未设置片段的选项。}

这是 Firebase 功能:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!")
})

这是我的 Swift 代码:

Functions.functions().httpsCallable("helloWorld").call { (result, error) in
  if error == nil {
    print("Success: \(result?.data)")
  } else {
    print(error.debugDescription)
  }
}

标签: swiftfunctionfirebasegoogle-cloud-firestoregoogle-cloud-functions

解决方案


如果您没有在客户端指定正确的区域,您可能会看到此错误。例如:

lazy var functions = Functions.functions(region: "europe-west1")

推荐阅读