Programming

iOS 시뮬레이터에서 네트워크를 비활성화 할 수 있습니까?

procodes 2020. 2. 23. 12:06
반응형

iOS 시뮬레이터에서 네트워크를 비활성화 할 수 있습니까?


인터넷에서 기본 데이터를 가져 오는 응용 프로그램에서 일관성없는 동작을 디버깅하려고합니다. 시뮬레이터의 문제는 장치에서만 볼 수 없으므로 시뮬레이터에서 네트워크 및 연결 환경을 재현하고 싶습니다.

시뮬레이터에서 네트워크를 비활성화하는 방법이 있습니까?

(저는 Mac에 원격으로 코딩하여 코드를 작성하고 있습니다. 지금은 다른 선택이 없으므로 OS 네트워크를 비활성화하는 것은 옵션이 아닙니다).


시뮬레이터가 OS가 사용하는 네트워크 연결을 공유합니다. 네트워크 상태 시뮬레이션에 관한 레이더 버그 보고서를 제출했습니다 . 같은 일을 고려할 수도 있습니다.


간단한 패러데이 케이지사용 하여 외부 RF 신호 레벨을 차단하거나 제한하십시오.

알루미늄 호일로 직접 만들 수 있습니다. 차단하려는 경우 개구부가 데이터 서비스 파장 보다 작아야합니다 .

800Mhz는 37cm (14 ") 파장, 1900Mhz는 16cm (6") 파장을 갖습니다.

패러데이 케이지 내부에서 Mac이 작동하기 어렵 기 때문에 시뮬레이터보다 실제 장치에서 더 잘 작동합니다. ;-)

여기에 이미지 설명을 입력하십시오


예. Xcode에서 Xcode메뉴 항목-> Open Developer Tools-> 로 이동하여 More Developer Tools" Xcode 용 추가 도구 "를 다운로드 하면 Network Link Conditioner가 표시됩니다.

이 도구를 사용하면 다양한 네트워크 시나리오 (예 : 100 % 손실, 3G, 대기 시간이 긴 DNS 등)를 시뮬레이션하고 고유 한 사용자 지정 시나리오를 만들 수도 있습니다.


내가 아는 iOS 시뮬레이터에서 네트워크를 비활성화하는 유일한 방법은 Little Snitch 또는 Hands Off 와 같은 도구를 사용하는 것 입니다. 그들과 함께 당신은 나가고 나가는 네트워크 연결을 거부 / 차단할 수 있습니다. 시뮬레이터 앱의 연결 만 차단하도록 설정할 수 있습니다. 방화벽처럼 작동합니다.


Mac OSX에서 WiFi를 끄면됩니다.


추가 도구 패키지 다운로드 (Network Link Conditioner)

기술

시에라의 예 : 여기에 이미지 설명을 입력하십시오

여기에 이미지 설명을 입력하십시오


현재 날짜로 답변을 업데이트하기 만하면됩니다. Xcode 4 (?)부터 /Applications/Utilities라는 환경 설정 창이 Network Link Conditioner있습니다. 기존 프로필 중 하나를 사용하거나 0Kbps Up / Downlink 및 100 % Drop 된 사용자 지정 프로필을 만듭니다.


Xcode는 이러한 기능을 제공하지 않으므로 타사 응용 프로그램 / 도구를 사용해야합니다. MAC 네트워크를 끄면 iOS 시뮬레이터 네트워크를 끄는 데 도움이됩니다.

" System Preferences..."> " Network" 에서 MAC 인터넷을 끄고 원하는 네트워크 소스를 끌 수 있습니다.

MAC 이더넷 인터넷 소스를 끄려면 : EtherNet 네트워크 소스

MAC WiFi 인터넷 소스를 끄려면 (MAC가 Wi-Fi 인터넷에있는 경우) : 여기에 이미지 설명을 입력하십시오


다음과 같은 타사 앱을 사용하여 인터넷 연결을 조절할 수 있습니다.

찰스 : http://www.charlesproxy.com/

스로틀 링을 설정하려면 Mac에서 command + shift + T를 누르십시오.


아마도 하나의 미친 아이디어 또는 패치 :

네트워크 연결성 플래그를 토글하기 만하면됩니다.

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 
}

You can use Little Snitch to cut off network traffic to any individual process, including ones that run on the iOS simulator. That way you can keep your internet connection and disconnect your running app.


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.


There are two way to disable IOS Simulator internet:

  • Unplug your network connection
  • Turn Wi-Fi off

It's the simplest way


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.


you could disable the network of the host instead!


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


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.

그런 다음 연결된 시뮬레이터를 실행해야하는 경우 종료하고 시작하십시오.


Mac에서 네트워크 링크 컨디셔너를 사용할 수 있습니다. Apple 개발자 웹 사이트에서 다운로드 할 수 있습니다. 이전 버전의 Xcode 및 iOS를 사용할 수 있어야합니다. 이 네트워크 컨디셔너를 사용하면 Wi-Fi에서 네트워크 없음으로 네트워크 강도를 변경할 수 있습니다.

또한 네트워크 컨디셔너를 설치하면 시스템 환경 설정에 설치됩니다.

참고 URL : https://stackoverflow.com/questions/4808433/is-it-possible-to-disable-the-network-in-ios-simulator



반응형