Xcode logo Xcode

Debugging with network conditions using Xcode

When developing apps, you are probably in an environment with stable and fast network connection, this is great while debugging. But how do we know the app will work in a less stable environment? Like when you are on the move switching from WiFi to a mobile network, or opening the app in the train while entering a tunnel? Does your app handle these use-cases correctly? 

Network conditions

Debugging with network conditions is really useful, you can quickly find out how your app response on average, bad, slow or even 100% loss in network.

Prio to Xcode 11, you can enable this by navigation to the developer settings in the settings app. In the develop settings you should be able to see the network link conditions under networking:

Network link condition settings
If you do not see the Developer option, you need to attach your iOS device with the Mac and select trust. Then open Xcode and select your attached iOS device. This will automatically unlock the Developer option in the settings app.

On the Network Link Conditioner settings page, you can see a list of profiles which you can use to manipulate your network condition. These profiles are only active when you select the enable switch at the top.
Note: This will effect all apps on your iOS device, not only your app. Do not forget to turn this off when you are done debugging!

Xcode 13

Starting in Xcode 13, debugging network conditions is so much easier! To enable, you attach your iOS device with the Mac and open the device menu in Xcode under Window -> Devices and Simulators or SHIFT + CMD + 2. 

Select your iOS device and scroll down to Device conditions. Here you can select to either use Network Link or Thermal State.

When you select Network Link, you can see much more profiles than the developer settings offers! After you chose a profile and select start, your iOS device will now have the selected network manipulation profile enabled for your app only! When you look at the iOS device, you should also notice that the status bar received a background color, meaning a device condition is enabled.

Network link conditions drop down menu

Xcode 13 will also automatically disable any device condition enabled when you stop debugging or detached your iOS device. Now you do not have to worry about disabling your conditions anymore!

Conclusion

Xcode 13 provides a more accessible way to debug network conditions and removes the reminder to turn off your device condition. I want to encourage you to try this out in your app to make your app more resilient!