iOS 呼叫 Firebase Functions Not Found
iOS 透過 Firebase SDK 呼叫 Google Cloud Functions 出現 NOT FOUND 的解決方式。

之前使用 Google Cloud Functions 都是製作 Http trigger 觸發器,只要帶入網址就可以呼叫 API,近期在幫我爸的物聯網控制 APP 大更新,需求是一些 API 不會開外部使用,只有認證過的使用者、APP 可以呼叫,結果 iOS 一直呼叫錯誤。
我在 Swift 中把錯誤都印出來,發現 Error Code = 5,說明是 NOT FOUND
let errorCode = error.code
let errorMessage = error.localizedDescription
print("錯誤代碼為:\(errorCode),錯誤訊息為:\(errorMessage)"
跑去 Firebase 後台看都是有抓到 Google Cloud Functions 內的 Function

全部的定義都有在這上面也百分之百確認呼叫的 function 已有部署成功,但這一看似乎看出端倪,依稀記得如果 Firebase 相關資源如果有定義資源位置,好像要手動指定。
於是我抱著試試看的心情,將原本以下的 functions 取得方式
private static var functions = Functions.functions()
改為
private static var functions = Functions.functions(region: "asia-east1")
果然最後可以正常運作!