xcode 如何在 iOS 模拟器中伪造网络连接类型更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11154253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fake network connection type changes in iOS simulator?
提问by Lvsti
I would like to test my iOS application with all the network conditions possible, including quality of the connection (offline, poor, good) and carrier (WiFi, 3G). For the former, others have already suggested using the Network Link Conditioner, e.g. here:
我想在所有可能的网络条件下测试我的 iOS 应用程序,包括连接质量(离线、差、好)和运营商(WiFi、3G)。对于前者,其他人已经建议使用 Network Link Conditioner,例如:
iPhone simulator - simulate 3G connection
which is just fine for the bandwidth and packet loss, but unfortunately it isn't able to change the carrier type that is reported to the simulator. So I'm looking for a not-so-hacky way of simulating changes in the carrier type. I said not-so-hacky because I have already come up with a hacky solution which, moreover, is incomplete as it can only deceive code which explicitly depends on Apple's famous Reachability
module. (Though if anyone is interested, I can post it here.)
这对于带宽和数据包丢失来说很好,但不幸的是它无法更改报告给模拟器的载波类型。所以我正在寻找一种模拟载体类型变化的不那么笨拙的方法。我说不那么hacky是因为我已经提出了一个hacky解决方案,而且,它是不完整的,因为它只能欺骗明确依赖于Apple著名Reachability
模块的代码。(如果有人感兴趣,我可以在这里发布。)
Is there a way to hiHyman/tamper with what the SystemConfiguration
API reports?
有没有办法劫持/篡改SystemConfiguration
API 报告的内容?
回答by Abizern
I use the excellent OHHTTPStubs
library to test these things.
我使用优秀的OHHTTPStubs
库来测试这些东西。
You even specify the types of connections you want to mock and their speed. And it's easy to create mock network returns in the tests. Which means you're not testing across an actual network so your tests are more determinate.
您甚至可以指定要模拟的连接类型及其速度。在测试中创建模拟网络回报很容易。这意味着您不是在实际网络上进行测试,因此您的测试更加确定。
回答by Daij-Djan
Use the Network Link Conditioner that the Xcode tools provides
使用 Xcode 工具提供的 Network Link Conditioner
install it using this: Installing Apple's Network Link Conditioner Tool
使用以下方法安装它:安装 Apple 的网络链接调节器工具