I'm building an iOS app using Firebase for the backend and need to use Firebase Callable Cloud Functions. I have everything set up as per docs and functions fire and behave as expected when launched from browser or curl but I cannot get them to fire from my app.
I've set up a test app just using the functions and I cannot get that to fire from iOS app either. Not even a basic hello world. Nothing is getting through.
All of the following has been done:
Firebase side:
- Firebase is connected to app successfully
- Installed/Initialised the Firebase Functions locally.
- Written function code in VSCode trying both Javascript and TypeScript
- Successfully deployed to Firebase and can see function in console
- Tested function via command line and browser on local server all works as expected
iOS side:
- Pod installed Firebase functions
- imported Firebase functions into ViewController
- Used Firebase SDK to invoke function matching name of function on Firebase - attached to button trigger
And I get nothing... the print statement on the button works but the function doesn't fire and nothing gets logged to Firebase logs.
What am I missing or doing wrong here?
Tried new project with new instance of Firebase. Copied code directly from examples on Firebase docs and followed everything step by step
FIREBASE CODE
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)
}
}
}
}