Is it possible to disable the network in iOS Simulator?

后端 未结 20 1263
名媛妹妹
名媛妹妹 2020-11-30 15:58

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

相关标签:
20条回答
  • 2020-11-30 16:32

    One probably crazy idea or patch :

    Just toggle the flag of network reachability

    This is code which I use to toggle my flag runtime by triggering 'Simulator Memory Warning' and its COMPLETELY SAFE, just make sure code should be in DEBUG Mode only

    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application 
    {
    #ifdef DEBUG
        isInternetAvailable = !isInternetAvailable;
    #endif 
    }
    
    0 讨论(0)
  • 2020-11-30 16:34

    A simple solution is to create an Airplane Mode for your Mac. Here is how to do this:

    • go into Network in System Preferences
    • click on Location dropdown menu
    • click on plus icon to add a new location
    • name the new location 'Airplane Mode' or similar, and click 'Done'
    • select the location you just created from the Location dropdown menu
    • click on each available network interface in the list at the left of the window in turn, disabling each one
    • click on the Configure iPv4 menu, and choose Off
    • for Wi-Fi, just click on the Turn Wi-Fi Off button
    • click Apply, and this location will block all network activity

    When you want to turn networking back on, just select Automatic from the Location dropdown menu, and click Apply

    • credit for this solution: http://hints.macworld.com/article.php?story=20130325002258846
    0 讨论(0)
  • 2020-11-30 16:34

    If you have at least 2 wifi networks to connect is a very simple way is to use a bug in iOS simulator:

    1. quit from simulator (cmd-q) if it is open
    2. connect your Mac to one wifi (it may be not connected to internet, no matters)
    3. launch simulator (menu: xCode->Open Developer Tool->iOs Simulator) and wait while it is loaded
    4. switch wifi network to other one
    5. profit

    The bug is that simulator tries to use a network (IP?) which is not connected already.

    Until you relaunched simulator- it will have no internet (even if that first wifi network you connected had internet connection), so you can run (cmd-R) and stop (cmd-.) project(s) to use simulator without connection, but your Mac will be connected.

    Then, if you'll need to run simulator connected- just quit and launch it.

    0 讨论(0)
  • 2020-11-30 16:35

    Download Additional tools package (Network Link Conditioner)

    Description

    Example in Sierra:

    0 讨论(0)
  • 2020-11-30 16:36

    you could disable the network of the host instead!

    0 讨论(0)
  • 2020-11-30 16:37

    Yes. In Xcode, you can go to Xcode menu item -> Open Developer Tools -> More Developer Tools and download "Additional Tools for Xcode", which will have the Network Link Conditioner.

    Using this tool, you can simulate different network scenarios (such as 100% loss, 3G, High latency DNS, and more) and you can create your own custom ones as well.

    0 讨论(0)
提交回复
热议问题