调用谷歌云函数的https函数时,Received Data为nil



我正在尝试我的第一个带有谷歌云功能的应用程序。我有一个简单的javascript函数,如下所示:

exports.updateisavaiable = functions.https.onCall((data) => {
const ref = admin.database().ref('/appinfo/actualversion');
ref.once("value", function (snapshot) {

const actualversion = String(snapshot.val());
const currentversion = data.currentversion;
console.log(currentversion);
console.log(actualversion);
let updateavailable;
if (actualversion > currentversion) {
updateavailable = true;
} else {
updateavailable = false;
}
console.log(updateavailable);
return(updateavailable);
});
});

当我用下面的代码在我的swift应用程序中调用这个函数时,我只得到";nil":

private func updateisavailable() {
//Überprüft ob ein Update verfügbar ist

let functions = Functions.functions()

functions.httpsCallable("updateisavaiable").call(["currentversion": CVersion.GetCleanVersion()]) { (result, error) in
//Wenn Update verfügbar, dann zeigt er eine Meldung
if let updateavailable = result?.data as? Bool {
if updateavailable {
CAlert.showBasicAlert(title: "Update available", message: "There is an update of schnitzelwithme available. Please download it in the app store to be sure, that you can use all functions of schnitzel with me!", vc: self)
}
} else {
print(error?.localizedDescription ?? "error could not be load")
}
}
}

在控制台中,我得到了正确的值(actualversion="0.6.3",currentversion="0.6.2",updateisavailable=true(。

我不知道这些函数有什么问题,也不知道为什么值为零。

您实际上并没有设置data,请尝试以下操作:

return({data: updateavailable});

最新更新