Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12, and Swift 5.3
- Be able to produce a "Hello, World!" iOS application (guide HERE)
However, the implementation for this uses my network manager, my API builder and a snippet to parse data
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!
The original App: The original App makes a network call and prints the following to the console:
{
error = "user not found";
}
We are going to change that response!
- Download Charles. It has a free trial, and after that has run it's course you are able to still use it (with restrictions)
- 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
This is confirmed with the following notification:
Now open the iOS simulator an enable the proxy certificate throughSettings>General>About>Certificate Trust Settings
you can then click the toggle to enable the proxy
You will be asked to confirm that you wish to do this in the simulator. Of course you should agree to this - Then run the App. You might like to run your own app that makes an API call, but I've created a usable App in the repo
- Run both Xcode and Charles
You can now run the App from Xcode, and at the same time run Charles.
If you press the request button on the App, you should see a request for regres.in
.
You can now see the request and the response!
Right-click on the regres.in
request and enable SSl proxying (This is also available from Proxy>SSL Proxying Settings).
- Enable rewriting
To mockTools > Rewrite
. Check Enable Rewrite.
Edit the location (this is the correct protocol, host and path for regres.in
)
We can then modify the query parameter
and then remember to click apply
- Run again - and we should have a result in the console of
{
eafsda = "user not found";
}
Charles is a great way of mocking a response,
If you've any questions, comments or suggestions please hit me up on Twitter