Use Charles to Rewrite Responses While Developing iOS Apps

You don’t need a backend (right now)

Prerequisites:

Terminology

Charles: A HTTP proxy for development

A warning

Be careful because many guides instruct developers to turn off the mac proxy, but using this simulator this prevents the developer seeing the data from their target App!

{
error = "user not found";
}

Step-by step instructions to change a response

  1. Download Charles. It has a free trial, and after that has run it’s course you are able to still use it (with restrictions)
  2. Get the Root Certificate for iOS simulators (this downloads the certificate straight to the simulator, without any work from you). This is available from the menu Help>SSL Proxying>Install Charles Root Certificate in iOS Simulators
{
eafsda = "user not found";
}

And remember…

If you want to use your usual backend (so to speak) do turn Charles off. If not, you know, you won’t be using your usual backend.

Also remember…

Caching goes on when using URLSession. When playing with the proxy this might mean that you don’t see the requests. In this case, you might choose to use URLSession ignoring the local cache — something like the following might help:

let config = URLSessionConfiguration.defaultconfig.requestCachePolicy = .reloadIgnoringLocalCacheDataconfig.urlCache = nillet session = URLSession.init(configuration: config)

And..remember…

If you want to mock a new host, make sure to pick one with an existing SSL certificate. That is, pick an already existing host!

Conclusion

Charles is a great way of changing responses, particularly if a backend has not been finished by your team. Helpful? I certainly hope that it is!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store