Error message from firebase functions shows 'Invalid request, unable to process.'

Viewed 463

I write a function and deploy it to firebase cloud functions, and I write a function in iOS to call it.

Cloud functions:

exports.verifyApp = functions.https.onCall((data, context) => {
    functions.logger.info(JSON.stringify(data));
    return {
        code: 200,
        msg: 'this is a message from the function'
    }
})

iOS function:

import FirebaseFunctions
import UIKit

class ViewController: UIViewController {
    let label: UILabel = UILabel()
    let button = UIButton(frame: CGRect(x: (UIScreen.main.bounds.width - 100) / 2, y: 100, width: 100, height: 50))
    override func viewDidLoad() {
        super.viewDidLoad()
        
        button.setTitleColor(.black, for: .normal)
        button.setTitle("Click", for: .normal)
        button.addTarget(self, action: #selector(test), for: .touchUpInside)
        view.addSubview(button)
        label.frame = CGRect(x: 20, y: 140, width: UIScreen.main.bounds.width - 40, height: 100)
        label.textColor = .blue
        label.textAlignment = .center
        label.numberOfLines = 0
        view.addSubview(label)
    }

    @objc private func test() {
        button.isEnabled = false
        label.text = "Request started"
        print("Request started")
        Functions.functions().httpsCallable("verifyApp")
            .call { [weak self] result, error in
                guard let self = self else { return }
                self.button.isEnabled = true
                print("Response => result: \(String(describing: result)) | error: \(String(describing: error))")
                if let error = error {
                    self.label.text = error.localizedDescription
                } else {
                    if let res = result?.data as? [String: Any] {
                        print("result: \(res)")
                        var text: String = ""
                        res.forEach { (key, value) in
                            text += "\(key)=\(value) | "
                        }
                        self.label.text = text
                    }
                    
                }
            }
    }
}

And now, it always shows:

Invalid request, unable to process.

firebase console screenshot

What can I do now? How to solve this issue? Can anyone help me?

0 Answers
Related