The proxy does not see iOS Simulator traffic

The Simulator goes online through macOS, so there is no proxy to set inside it. It needs the system proxy on the Mac and the root certificate inside the Simulator, fully trusted.

How the Simulator goes online

The iOS Simulator is a process on your Mac. It uses the macOS network stack and proxy settings, so:

  • there is no proxy to set in the Wi-Fi settings inside the Simulator;
  • localhost in the Simulator is your Mac, and a local development server opens at the same address as in the browser on the computer.

But the Simulator has its own certificate store, and the root certificate in the Mac's keychain does not reach it.

Step 1. The proxy in macOS

A debugging proxy sets itself as the system proxy on start. Check:

scutil --proxy

Expect HTTPEnable : 1 and HTTPSEnable : 1. If zero, set it by hand: System Settings → Network → the active connection → Details → Proxies → Web proxy (HTTP) and Secure web proxy (HTTPS), 127.0.0.1 and the proxy's port. The setting is per connection: a proxy set for Wi-Fi does nothing while the Mac is on Ethernet.

Step 2. The certificate in the Simulator

Start the Simulator, convert the certificate to DER and install it:

openssl x509 -in proxy-ca.pem -outform der -out proxy-ca.cer
xcrun simctl keychain booted add-root-cert proxy-ca.cer

With several simulators running, booted picks one of them. Pass a UDID from xcrun simctl list devices for each instead. Then restart the Simulator: running processes may keep the old trust list.

By hand: drag the .cer file onto the Simulator window (PEM does not work), install the profile under Settings → General → VPN & Device Management, then turn on trust: Settings → General → About → Certificate Trust Settings. Same step on an iPhone: iOS: the profile is installed but the certificate is not trusted.

Why it still does not work

A new simulator. A new one, or one reset with Erase All Content and Settings, has no certificate. Repeat step 2.

A VPN on the Mac. It can take over the system proxy settings. See proxies and VPNs.

The app ignores the system proxy. URLSession and WebKit honour it. Libraries with their own network stack (gRPC over its own sockets) or raw TCP code go around it.

Pinning. The app rejects any certificate not on its own list. All causes: why a proxy does not see an app's traffic.

localhost in the exceptions. Requests to a local dev server missing? Check the macOS proxy exceptions: the proxy not seeing localhost.

See it on your own traffic

In Solpuga the iOS Simulator wizard in the SSL Certificate menu does this. It runs on macOS and needs Xcode Command Line Tools and at least one running simulator. If HTTPS requests still hang pending, turn on trust by hand as in step 2. Details: Mobile Devices.

View in Solpuga

Related