Failed to send a request (iOS Simulator Bug)

When you’re deep in development, you expect bugs, but sometimes they’re not where you expect. I spent significant time chasing a bug caused, not by me, but by the iOS simulator itself.

Let’s look at what happened.

Bluesky
Threads
Twitter / X
Mastodon
Instagram

The Setup and the Phantom Error

I was working on a feature that used OpenAI’s realtime voice API. To do this securely, the client-side React Native app needed to get a temporary session token from a Supabase Edge Function.

The process should be simple:

  1. The app calls the Supabase function.
  2. The function calls OpenAI to get a session token.
  3. The function returns the token to the app.

When I tested the edge function directly using Postman, it worked perfectly every time. But when the app tried to make the exact same call from the iOS simulator, it failed with a cryptic error:

[FunctionsFetchError: Failed to send a request to the Edge Function]

This immediately pointed to a Cross-Origin Resource Sharing (CORS) issue, a common problem when a client app tries to communicate with a backend on a different domain. And so, the debugging began.

The Debugging Rabbit Hole

The logical first step was to attack the presumed CORS issue. I meticulously configured the CORS headers in my Supabase Edge Function, ensuring it would accept requests from any origin.

// client/supabase/functions/_shared/cors.ts

export const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
  "Access-Control-Allow-Methods": "POST, OPTIONS",
}

After deploying the changes, the error remained. Over the next few days, I tried everything I could think of to isolate the problem, with the error message sometimes changing to an even more generic [TypeError: Network request failed].

  • Bypassing the Supabase Library: I rewrote the call to use a direct fetch instead of supabase.functions.invoke, thinking it might give me a more detailed error. It didn’t.
  • Confirming Network Connectivity: I added a test fetch call to a known-good public API (like GitHub). This worked perfectly, proving the app could make network requests, just not to my Supabase function.
  • Intense Server-Side Logging: I added detailed logs to every single line of the edge function to see if the requests were even reaching the server.

This last step was the key turning point. The logs showed my requests from Postman arriving and succeeding every time. But requests from the iOS simulator never appeared in the logs at all.

It meant the requests were being blocked before they even hit my function’s code. The code was right, the server config seemed right, but the connection simply wouldn’t go through.

The Solution:

When All Else Fails, Blame Your Tools.

After a while, the only variable left seemed to be the environment itself. I saw a hint online to try running the app on a different simulator. I had been using the latest iOS 18.4 simulator. I switched to an older iOS 17.5 simulator, re-ran the app, and it worked. Instantly.

The “impossible” bug was a glitch in the iOS 18.4 simulator.

How to Switch Your iOS Simulator

If you find yourself in a similar situation, changing the simulator is straightforward.

  1. Open Xcode and go to Settings > Platforms.
  2. Click the + icon in the bottom-left and select “iOS…”.
  3. Choose an older, stable iOS version from the dropdown and click “Download & Install”.
  4. Once installed, you can select this new simulator as the build target either from your IDE’s device list or by using the --simulator flag in the React Native CLI, like so:
    npx react-native run-ios --simulator="iPhone 15 (17.5)"
  5. Close the problematic simulator and let the build process open the new one.

That’s it!

References:

Thanks…

I also dissect and speculate on design and development.
Digging into subtle details and implications, and exploring broad perspectives and potential paradigm shifts.
Check out my conceptual articles on Substack or find my latest below.


You can also find me on Threads, Bluesky, Mastodon, or xTwitter for more diverse posts about ongoing projects.

My latest articles

Storyboarding Immersive Experiences

Storyboarding 360 degree immersive experiences requires a different approach to traditional media…

Staging XR scenes (Keep doing your crappy little drawings)

Some people create beautiful perspective illustrations to visualise and storyboard their virtual reality designs And it’s tempting to think you’re not a strong designer if you’re not doing that too…

Focal point blocking for XR media

Planning out a linear VR experience requires thinking about where the viewers attention might be. Thinking about the focal points…

Designing immersive experiences

In traditional cinema, TV, or even the more modern phone screen, there’s limited screen real-estate. But removing that limitation creates a design problem…

The future is not prompt engineered

Let’s not pretend the importance of prompt engineering is ubiquitous. The most prevalent power of generative AI is in the way it adapts to us, not the other way around…

The typography of dates, times, & filenames

A deep dive into carefully considered date formatting, line length and general typography attributes of filenames…
Bluesky
Threads
Twitter / X
Mastodon
Instagram


Author:

Date:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.