How to monitor network calls made from iOS Simulator
Asked Answered
C

18

165

I am trying to monitor calls from an app to my server just like Firebug does. I could not find a way to see that in iOS Simulator or in xCode.

Is there a way to do that without sniffing all the traffic? If no, what tool would you suggest?

Coincidence answered 20/6, 2012 at 21:19 Comment(0)
N
109

Personally, I use Charles for that kind of stuff.
When enabled, it will monitor every network request, displaying extended request details, including support for SSL and various request/reponse format, like JSON, etc...

You can also configure it to sniff only requests to specific servers, not the whole traffic.

It's commercial software, but there is a trial, and IMHO it's definitively a great tool.

Nuthouse answered 20/6, 2012 at 21:31 Comment(3)
Really easy to use and configure and does exactly what I wanted, thanks!Coincidence
Doesn't easily work when your server is protected by TLS, which it should be.Gittens
I tried Charles but I was not able to monitor outgoing traffic very well. For instance, I coudn't change the formatting of my POST request into JSONVelasquez
R
29

A man-in-the-middle proxy, like suggested by other answers, is a good solution if you only want to see HTTP/HTTPS traffic. Burp Suite is pretty good. It may be a pain to configure though. I'm not sure how you would convince the simulator to talk to it. You might have to set the proxy on your local Mac to your instance of a proxy server in order for it to intercept, since the simulator will make use of your local Mac's environment.

The best solution for packet sniffing (though it only works for actual iOS devices, not the simulator) I've found is to use rvictl. This blog post has a nice writeup. Basically you do:

rvictl -s <iphone-uid-from-xcode-organizer>

Then you sniff the interface it creates with with Wireshark (or your favorite tool), and when you're done shut down the interface with:

rvictl -x <iphone-uid-from-xcode-organizer>

This is nice because if you want to packet sniff the simulator, you're having to wade through traffic to your local Mac as well, but rvictl creates a virtual interface that just shows you the traffic from the iOS device you've plugged into your USB port.

Reflection answered 21/6, 2012 at 4:48 Comment(1)
+1 for Burp Suite, and no pain to configure it: engadget.com/2011/02/21/… It takes less than 10 minLaing
K
27

Xcode provides CFNetwork Diagnostic Logging. Apple doc

To enable it, add CFNETWORK_DIAGNOSTICS=3 in the Environment Variable section:

enter image description here

This will show requests from the App with its headers & body. Note that OS_ACTIVITY_MODE must be set to enable as shown. Otherwise no output will be shown on the Console.

Klausenburg answered 11/9, 2018 at 1:23 Comment(1)
OS_ACTIVITY_MODE is no longer required per the latest doc: developer.apple.com/documentation/network/…. Also need to use the separate Console app on your mac, not look for messages in Xcode's Debug console. From the doc: "Make sure you select your iOS device from the source list on the left of the main Console window (choose View > Show Sources if the source list is not visible)." From there you can add filters for e.g. your process, cfnetwork, HTTPProtocol: request etc. (right click on a row or use the search box)Crocidolite
D
23

Recently i found a git repo that makes it easy.

You can try it.

This is an app's screenshot: enter image description here

Best regards.

Dahabeah answered 13/2, 2019 at 22:21 Comment(3)
While Bagel is great and simple, I recently noticed that it will also show cached requests. So if you want to know the actual transferred bytes, for example, this is not helpful.Courtneycourtrai
Coming from web development, this is the most simple and similar tool to the network tab you will find in browsers. I really like this tool.Kristopher
The SPM is broken before anyone else wastes their time.Cineaste
A
21

A free and open source proxy tool that runs easily on a Mac is mitmproxy.

The website includes links to a Mac binary, as well as the source code on Github.

The docs contain a very helpful intro to loading a cert into your test device to view HTTPS traffic.

Not quite as GUI-tastic as Charles, but it does everything I need and its free and maintained. Good stuff, and pretty straightforward if you've used some command line tools before.

UPDATE: I just noticed on the website that mitmproxy is available as a homebrew install. Couldn't be easier.

Appoggiatura answered 23/5, 2013 at 3:30 Comment(2)
Have you had any luck using mitm for the iOS simulator? I have it setup but the traffic from my computer outside of the simulator is also caught, which is not the best. Using it on an actual device is amazing. Been doing it for years.Cheat
mitmweb is mitmproxy’s web-based user interface that allows interactive examination and modification of HTTP traffic. Like mitmproxy, it differs from mitmdump in that all flows are kept in memory, which means that it’s intended for taking and manipulating small-ish samples mitmproxy.readthedocs.io/en/v2.0.2/mitmweb.htmlShunt
P
12

as from Xcode 13 you can monitor all network traffic with all of its details using Xcode Instruments -> Network instrument. you need a physical device running iOS 15+ on macOS 12+

more details can be found on Analyze Network Traffic in WWDC 2021 videos.

Predicant answered 2/9, 2021 at 13:26 Comment(1)
The question is explicitly asking how network traffic can be monitored while using a simulator, not a physical device.Glycoside
T
9

For monitoring https requests you basically need to follow two broad steps:

In case you just want a step-by-step guide, skip to the TLDR at the end.


  1. Setup a man-in-the-middle proxy (like Requestly, Charles, or HTTP toolkit) and start sending traffic to it

You could use tools that listen to all your system’s traffic, but in my experience, you just end up with too many logs than you know how to navigate and filter out.

A better (and more obvious) approach would be to only intercept and monitor the traffic from the iOS simulator.

You can do this by editing your Xcode project’s schema

Edit Xcode Schema

and defining two variables http_proxy and https_proxy

HTTP proxy environment variables

Set these appropriately to send all traffic to your proxy. Most of them always mention the IP and port on which their proxy is running.

This is all you need to do if your app does not use encryption (which it probably does), in which case, you will need to also handle encryption


  1. Using your proxy’s self-signed certificate to encrypt the request. Then the proxy is able to decrypt and read the contents of the requests — allowing you to properly debug and monitor your app’s traffic,

Download the self-signed root certificate of your proxying tool inside the iOS simulator. Most proxying tools provide an http endpoint to make it easy to add this to your simulator once the proxy has been configured. Eg, chls.pro/ssl or proxy.man/ssl or requestly.io/ssl

on iOS, this certificate is meant to create a custom profile that adds the proxy’s certificate to the simulator’s certificate chain.

To install profile after it has been downloaded, go to Settings > General > Device Management

Install custom profile

Here you will see the details of the downloaded profile and the option to install it.


Once that's done, you need to enable trust for the newly added certificate.

For this, go to Settings > About > Certificate Trust Settings and enable trust for the downloaded certificate

Trust custom profile

Now you should be able to monitor your http and https traffic, without iOS complaining that something malicious is happening.

Disclaimer and TLDR: I actively maintain the Requestly Desktop App and here’s a short step-by-step guide to setup iOS simulator monitoring with Requestly — https://docs.requestly.io/guides/debugging-https-traffic-in-ios-simulator

Treytri answered 13/4, 2023 at 21:36 Comment(0)
S
7

Wireshark it

Select your interface

enter image description here

Add filter start the capture

enter image description here


Testing

Click on any action or button that would trigger a GET/POST/PUT/DELETE request

You will see it on listed in the wireshark

enter image description here

If you want to know more details about one specific packet, just select it and Follow > HTTP Stream.

enter image description here

hope this help others !!

Snowball answered 9/10, 2018 at 13:16 Comment(1)
How to know more details with the request is an HTTPS (not HTTP)?Evangelista
T
6

It seems this may have recently been added. Clicking command + control + z on the simulator will pop up a debug menu. From that menu, click Inspect. Inspect will present tabs. Click the network tab and that will show all network requests being made.

Tattle answered 3/9, 2020 at 16:10 Comment(4)
This is cool, but it blocks the bottom of the simulator rendering it unusable. facepalm Any way to move it?Chimborazo
Yes I believe you can move the output window to the top of the simulator. It is aggravating and sometimes you will have to move output screen from bottom to top of simulator and vice versa.Tattle
What exactly do you mean by recently, please provide your xcode version.Foreclosure
i reckon he's mentioning the network from React Native -- it only shows calls triggered by react/js code either way, not everything that goes thru the network pipeline.Jenninejennings
I
3

If you have cable connection and Mac, then there is simple and powerful method:

  1. install free Wireshark, make sure that it can capture devices with (and you need to do this after every computer restart!):

    sudo chmod 644 /dev/bpf*

  2. Now share your network with wifi. System preferences > Sharing > Internet Sharing. Check that you have "Share your connections from: Ethernet" and using: Wi-Fi. You may want to also to configure some wifi security, it does not disturb your data monitoring.

  3. Connect your phone to your newly created network. I need quite often several attempts here. If the phone does not want to connect, turn of wifi of Mac, then repeat step 2 above and be patient.

  4. Start Wireshark capture your wireless interface with Wireshark, it is probably "en1". Filter your needed IP addresses and/or ports. When you find a package which is interesting, select it, Right-click (context menu) > Follow TCP Stream and you see nice text representation of the requests and answers.

And what is the best: exactly the same trick works for Android also!

Inscribe answered 11/9, 2012 at 10:11 Comment(2)
Can you use this with your simulator? I don't have the app on my phone yet.Ozoniferous
@Joshua Dance you can use it with emulator, if it does external network request. Connections to localhost cannot be traced with wireshark, as they are not passing the "wire" (network card)Inscribe
C
2

Telerik Fiddler is a good choice

http://www.telerik.com/blogs/using-fiddler-with-apple-ios-devices

Cockspur answered 1/2, 2017 at 8:39 Comment(4)
How will that work on an OSX-machine? Considering two of the tags are xcode and ios-simulator.Fiend
@KevinR, 1. Telerik does have beta version of Fiddler for OS X 2. Nowhere in the question is said that the choice is limited to OS X telerik.com/blogs/using-fiddler-with-apple-ios-devicesCockspur
@KonstantinSalavatov, The subject of the original post is "How to monitor network calls made from iOS Simulator". The iOS Simulator only runs on OS X, so yes, the choice is limited to OS X.Grous
+1 I think you should upvote this now, because there is support for Mac OS X now ! :D telerik.com/fiddler#SupportedTechnologies and here telerik.com/download/fiddler/fiddler-osx-betaSchoolmistress
C
2

FLEX is a great tool to monitor network traffic from your iOS app.

FLEX iOS Screenshot 1

On clicking on any of the requests listed in the above screenshot, I will be redirected to another screen where I can see more details about that request. FLEX iOS Screenshot 2

However, I had a use case where the app which I was working on would redirect the user to Safari. I wanted to monitor the network traffic in Safari as well, but FLEX could only monitor the traffic from your iOS app, not from any other app ( at the time of writing this answer ).

Then I switched to Proxyman to monitor network traffic from the iOS simulator.

  • It has a clear set of instructions on how to set it up with both iOS simulators and Android emulators.
  • It has a simple, intuitive UI, which makes it easy to work with.

enter image description here

Castaneda answered 1/2, 2021 at 13:14 Comment(1)
I loved proxyman. Very good docs. If you already have Homebrew installed, then it's just "brew install proxyman".Isolate
G
1
  1. Install WireShark
  2. get ip address from xcode network monitor
  3. listen to wifi interface
  4. set filter ip.addr == 192.168.1.122 in WireShark
Gilgai answered 14/2, 2018 at 19:36 Comment(0)
F
1

I use netfox. It is very easy to use and integrate. You can use it on simulator and device. It shows all of the requests and responses. It supports JSON, XML, HTML, Image and Other types of responses. You can share requests, responses and full log by IOS default sharing formats (Gmail, WhatsApp, email, slack, sms, etc.)

You can check on GitHub: https://github.com/kasketis/netfox

Netfox provides a quick look on all executed network requests performed by your iOS or OSX app. It grabs all requests - of course yours, requests from 3rd party libraries (such as AFNetworking, Alamofire or else), UIWebViews, and more

Fourway answered 11/1, 2019 at 7:5 Comment(0)
T
1

You can also use this open source library called Wormholy (and made by me).

You just need to integrate it in your project (no code needed), and that's it, you will be able to monitor all the API requests of your app, also on a real device.

And you don't need to manage certificates like with Charles. It all works by magic!

Tabriz answered 7/9, 2020 at 9:56 Comment(1)
Seems really nice ! I tried to install it but I didn't see it only tracks traffic from NSURLSessionHanna
Z
0

A good solution if you are used to the chrome inspector tools is Pony debugger: https://github.com/square/PonyDebugger

It is a bit of a pain to setup, but once you do it work well. Be sure to use Safari instead of Chrome to use it though.

Zelig answered 14/6, 2015 at 11:13 Comment(0)
J
0

You could try to use https://github.com/BugBlock/BugBlock-iOS it's a small tool I created, so everything you need is:

import BugBlock

then

var config = BBConfiguration()
config.consoleLoggingEnabled = false
config.serverLoggingEnabled = true
config.crashReportingEnabled = true
BBLog.start(appId: "SDK key", configuration: config)

and setup network interceptor

let conf = URLSessionConfiguration.default
BBLog.networkLogging(with: conf)
let session = URLSession(configuration: conf)

Then use the session in your requests. Hope that helps you to catch logs.

Judgemade answered 16/11, 2021 at 14:1 Comment(0)
N
0

Nowadays I find Proxyman the best solution for that and in our development team everybody uses that as well. Its clear UI with rich options is for me far better than other tools

Nyx answered 2/1 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.