firebase-ios-sdk: Calling Cloud Functions locally from iOS gives an "Insecure fetch request" error

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 12.4
  • Firebase SDK version: 7.6.0
  • Installation method: Swift Package Manager
  • Firebase Component: Functions

[REQUIRED] Step 2: Describe the problem

When running the emulator locally and calling a HTTPS function, the console outputs the following message:

 Insecure fetch request has a scheme (localhost) not found in fetcher allowedInsecureSchemes ((
    http
)): localhost:5001/****/us-central1/testFunction

Steps to reproduce:

Create a cloud function:

Run the emulator locally

Setup the iOS app to call your function and call it

Relevant Code:

exports.testFunction = functions.https.onCall(async (data, context) => {
}
firebase emulators:start

on iOS:

            let functions = Functions.functions()
            functions.useEmulator(withHost: "localhost", port: 5001)

            functions.httpsCallable("testFunction").call([ ...

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

The “http” prefix should not be required in useEmulator, that’s a bug. So I’ll fix that which means that the workaround presented in this Issue will break in the future (just FYI)

@ir-fuel @peterfriese A couple changes I had to do to make emulator working for me:

  • with the current SDK implementation the host parameter should contain the protocol part as well, e.g.
functions.useEmulator(withHost: "http://localhost", port: 5001)
  • App Transport Security must be configured to allow local networking:
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsLocalNetworking</key>
		<true/>
		<key>NSAllowsLocalNetworkingUsageDescription</key>
		<dict>
			<key>localhost</key>
			<dict>
				<key>NSIncludesSubdomains</key>
				<true/>
				<key>NSExceptionAllowsInsecureHTTPLoads</key>
				<true/>
			</dict>
		</dict>
	</dict>

Please let me know if these changes are sufficient for you as well.

@ir-fuel Let me try it on my end and get back to you.