iOS Simulator - offline mode
Does anybody know how to mak开发者_如何学运维e the iPhone/iPad simulator become offline?
Regards!
Install Little Snitch and temporarily block all connections from iOS Simulator when the dialog comes up.
If you set os x offline, the iPad simulator will be offline. Otherwise, no.
There's a tool called "Network Link Conditioner" but it seems that its only for OX Lion and xCode 4.1+ installed. Take look at: http://osxdaily.com/2011/08/10/simulate-internet-connectivity-bandwidth-speeds-network-link-conditioner/ - i use it almost everyday :)
Install Network Link Conditioner from Apple. And you will have possibility to change to offline mode.
If you want to test something in the local environment like a web app for iOS with cached features, you can add a rule to your hosts file pointing to your localhost, then you can comment the line every time you desire to make it inaccessible.
Ideally, all app's network communication goes through one point. By commenting out a relevant code or creating a dummy error it's rather straightforward to make it look like all the responses have timed out.
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// if (error) {
if (self.delegate) {
[self.delegate networkError: error];
}
// } else {
I find it good enough for the actual development. It's quick and cheap, even if a bit dirty, while allowing to continue working without the hassle of a constant WiFi toggling. Once successfully enabled, even pretty specific scenarios are easy to simulate.
When the work is finished, turning off macOS WiFi for the final testing is a good idea, though.
On macos, turning off wifi and plugging your phone with USB hotspot mode on works a treat. Simple and reliable for everything including testing reachability.
精彩评论