I am trying to debug some inconsistent behaviour I am seeing in an application that gets its primary data from the internet. I don\'t see the issues in the simulator, just
With Xcode 8.3 and iOS 10.3:
XCUIDevice.shared().siriService.activate(voiceRecognitionText: "Turn off wifi")
XCUIDevice.shared().press(XCUIDeviceButton.home)
Be sure to include @available(iOS 10.3, *)
at the top of your test suite file.
You could alternatively "Turn on Airplane Mode" if you prefer.
Once Siri turns off wifi or turns on Airplane Mode, you will need to dismiss the Siri dialogue that says that Siri requires internet. This is accomplished by pressing the home button, which dismisses the dialogue and returns to your app.
The only way to disable network on iOS simulator I know is using tools like Little Snitch or Hands Off. With them you can deny/block any out- and ingoing network connections. You can set it up so that it only blocks connections from the simulator app. Works like a firewall.
You could use OHHTTPStubs and stub the network requests to specific URLs to fail.
If your app is connecting to a specific domain, you can simply add it to your /etc/hosts
file and route it to a non-existing IP in your local network... For the application it will be the same as if there was no internet connection or the server is not reachable.
sudo nano /etc/hosts
add the following line:
192.168.1.123 example.com
or use 127.0.0.1
if you are not running a webserver on your local machine.
Use a simple Faraday cage to block or limit the external RF signal level.
You can make your own with aluminum foil. The openings should be smaller than the wavelength of your data service if that's what you want to block.
800 Mhz has a 37 cm (14") wavelength, 1900 Mhz has a 16 cm (6") wavelength.
This works better with an actual device than with the simulator since the Mac is hard to work on when inside the Faraday cage ;-)
I would suggest you using Charles Proxy app on Mac
It allows you using Bandwidth Throttle
feature that was created just for adjusting network connection
Star/Stop Throttling ⌘ command + T
Throttle Settings... ⌘ command + T + ⇧ shift
*If you create you own Preset via Add Preset
with Bandwidth 0 and 0 for Download and upload you can simulate no Internet connection. Also it is very useful to enable it only for some specific hosts
As an alternative you can disable your connection on Mac because all traffic from Simulator go thought your computer