Closed
Description
Step 1: Describe your environment
- Xcode version: 12.4
- Firebase SDK version: 7.6.0
- Installation method:
Swift Package Manager
- Firebase Component: Emulators , Functions
Step 2: Describe the problem
Steps to reproduce:
- Create a new Firebase project via the console
- Create a new local Firebase project using the CLI
- Enable Functions and Emulators
- Enable the Functions and Auth Emulators
- Use the default ports for setting up the emulators
- Implement a simple callable
helloWorld
function (see below) - Launch the emulators (
firebase emulators:start
) - Create a new (SwiftUI) project
- Download
GoogleService-Info.plist
and add to project - Enable
App Transport Security
(allow arbitrary loads) - Initialise the emulators (see Swift code below)
- Call
helloWorld
callable function from Swift (see code below)
Expected behaviour
- It is possible to call the
helloWorld
callable function from the iOS app
Observed behaviour
GTMSessionFetcher
issues error message abouthttp
not being in list of allowed insecure schemes:
2021-02-16 16:32:29.570523+0100 FirebaseEmulatorDemo[47823:2419456] Insecure fetch request has a scheme (localhost) not found in fetcher allowedInsecureSchemes (( http )): localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld Error Domain=com.google.GTMSessionFetcher Code=-5 "(null)" UserInfo={NSErrorFailingURLStringKey=localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld}
Relevant Code:
Callable Function:
exports.helloWorld=functions.https.onCall((data,context)=>{return{message: "Hello World from Firebase"};});
Swift code for initialising emulators and calling the Function
classFirebaseEmulatorDemo:ObservableObject{ lazy varfunctions=Functions.functions()init(){FirebaseApp.configure() // set up emulators Auth.auth().useEmulator(withHost:"localhost", port:9099) functions.useEmulator(withHost:"localhost", port:5001)}func helloWorld(){lethelloWorld= functions.httpsCallable("helloWorld") helloWorld.call(){ result, error iniflet error = error {print(error)}else{iflet message =(result?.data as?[String:Any])?["message"]as?String{print("The function returned: \(message)")}}}}}
Related material
- Firebase Auth Emulator Fails Over Local Network #7342 mentions a similar issue
- It is interesting to note that these lines of code do suggest that the expected behaviour should indeed work:
firebase-ios-sdk/Functions/FirebaseFunctions/FIRFunctions.m
Lines 247 to 251 in 02488e9