Apple wants me to give the user a friendly apology if I can't find an internet connection. Using the Reachability Demo, this was easy enough. I want to take it a step further and monitor for a connection loss. The demo has this functionality, but I can't figure out how to shut my connection off to test if it works.
How would I go about simulating a loss of (or actually losing) a connection?
If you're developing in the iPhone Simulator, simply disconnect your computer from the internet. If your computer has no network access, neither does the iPhone Simulator.
To test on the device, you can do the following:
First, setup a WiFi router that you can use for testing.
You can turn on Airplane mode on the phone, then turn WiFi back on. This will prevent the 3G connection from providing data access.
Launch your application. Now you can simply disconnect your WiFi router to simulate a loss of connectivity.
You can use the SpeedLimit preference pane to simulate network latency under the simulator. And here's a command line version built on top of the ipfw command.
The advantage over just yanking the cord or killing WiFi is that you can specify the speed when hitting specific hosts so it can be used for testing without killing your regular network services.
You could install Apple's Network Link Conditioner
On Yosemite:
Network Link Conditioner can be found in the "Hardware IO Tools for Xcode" package. This can be downloaded from the Apple Developer Downloads page. Once the download has finished, open the DMG and double-click "Network Link Condition.prefPane" to install (source).
With this preferences panel you could create a profile with 0kbps speed.
On older versions of OSX:
Mountain Lion / Mavericks: Xcode > Open Developer Tool > More Developer Tools
Lion: /Developer/Applications/Utilities/Network Link Conditioner
For testing in the simulator I make great use of Little Snitch. It's a very useful application for writing rules as to what can communicate with the outside world and for how long.
It will also notify you if an application wishes to access the internet on the fly and you can temporarily restrict access for either that time, that session or forever.
As for testing on the device, I log into my wireless router and temporarily disable either the network or turn on restriction by MAC ID for the duration of the test.
Use Charles Web Proxy
You can inspect all HTTP/S requests your app sends and responses it receives, throttle connection to simulate any network speed. Create custom throttle profile called "Disconnected" with Bandwidth = 0, to simulate network disconnections.
Perhaps this preference pane is also useful for you: SpeedLimit.prefPane it can't loose the connection, but you can slow down it based on the host and port you're trying to reach.
Searching for similar need i.e. simulating a lossy wifi network connection on real device, I figured out how to do it :)
I connected my MacBook Pro on ethernet and shared my Wifi connection to the device.
Using Apple's Network Link Conditioner Prefpane then let me played with the connection quality.
Very useful to simulate 3G, Edge and other baudrate.
Next step : find and buy a usb wifi adapter working on MAC OS X to let all of us (developpers team) to test without wiring each computer to ethernet.
Hope this will help some of you.
Related
Most electronic home goods today are able to be setup through a webpage to connect the device to a home network. Usually there is some sort of bluetooth or wifi direct finding mode to access the device and then using a webpage or app the device is given the SSID/password for a wifi network and then you're off to the races. What is that tech called? I would like to replicate the setup experience with a generic IoT device running linux. I just don't know what that process is called to start digging into how to do it.
Bluetooth and Wifi-direct specifications are (consumer-usage-wise) public-domain knowledge, just setup a temporary open server and accept any connection after each hard-reset, and do what you have to do like here (BT) and here (Wifi-direct). There are other proprietary technology like TI CC3000, which usually relates to specific hardware solutions.
I am developing an app that needs to be debugged under a slow connection. My issue is that I only own an iPhone 5 that uses LTE. I can disable LTE in my Settings for a 4G connection but this 4G connection is still to fast for my testing purposes. I would like to know if there is a way to programmatically force the testing iPhone into 3G or EDGE.
You'll want to test flaky in addition to just going slow - you can simulate this with apple's network link conditioner and running your iPhone through your mac's internet connection (or run simulator). See Installing Apple's Network Link Conditioner Tool .
If you really want some good testing, the best way to do it is look up your cell provider's coverage map and find some crappy locations. Test in those areas while driving in and out of range should weed out any broken network code you have. :)
Network Link Conditioner also exists on the device in recent iOS builds, i'm not positive of when they added it.
But its present in Settings, under the Developer menu.
I can disable LTE in my Settings for a 4G connection but this 4G connection is still to fast for my testing purposes
LTE is (a kind of) 4G.
If you disable it, it will fall back to EDGE. Alternatively, you may switch to a Wi-Fi connection and slow it down (if your router has such a feature).
I want to create an iPhone application that can call web services on a computer, and then upload those files over the iPhone 3g connection. Is there an elegant way to do this?
I tried connecting the phone to local Wifi, but connecting to Wifi disables 3g, even though the Wifi is local network only.
I assume the same problem would arise if I could network the phone with the computer via bluetooth.
Any other ideas? The purpose is to go up to a special demo PC we created, pull some data off, then upload to the Internet, all within proximity of the machine. Unfortunately, it appears that I can't use one connection for pulling data, and another for pushing.
Your assumption is correct. When connecting to both 3G and Wifi, the Wifi connection will be used. Sounds like your local network has no route to the Internet. Perhaps that could be fixed.
Apple does not prefer its iPhones to be used as routers.
If you're working on something that will not be distributed through the App Store, you may have some success looking at "tethering" applications and their source code, which can be found by some clever Googling.
We are in the process of developing an method of caching so that our app can continue to operate in an area with very little/no signal.
Obviously users will try to continue to use functions that require data and we need to handle the inevitable failure of these requests appropriately.
Essentially we are sat in the office, switching airplane mode on and off to simulate entering/exiting signal then adjusting our app to fix any issues this may arise.
What I'd like to know is, is using airplane mode going to give us a reasonable simulation of entering/exiting an area with no data or are there other implications?
I've seen questions raising the issue that the 3G/EDGE connection may not always wake up after airplane mode is switched on - while I appreciate this method is no way as good as actually being out in the field testing, if we can get a reasonable simulation and account for the majority of the problems that arise then I think this is an acceptable tradeoff.
I apologise if this has been asked before, I did do a search on here & on google but couldn't find any appropriate results.
You should try the Network Link Conditioner
There is a WWDC 2012 session called Networking Best Practices that mentions it (but he does not explain how to use it there).
To get it, you have to go to XCode/Open Developer Tool/More Developer Tools.. and download the latest Hardware IO Tools for XCode.
Once you install it from the IO Tools pkg, "Network Link Conditioner" will appear in System Preferences
You can then do something like 100% packet loss to simulate one of those routers that pretends you are connected but actually doesn't work.
On iOS, the network link conditioner is under Settings / Developer (you must have enabled Developer mode in XCode first to see it)
The main problem is that in the Airplane Mode the networking operations fail fast, while spotty mobile signal will lead to timeouts and a-few-bytes-an-hour speeds. This is usually a significant difference from the UI viewpoint. (It might be worth a try to use some bandwidth throttle to starve the testing machine and see how it behaves when the network starts to break?)
A few years back, when testing remote devices which used the cell network to communicate with the 'home base', we did things like move them into a shielded room (make shift), place large shields on three of four sides to force them to connect to a certain tower (and therefore, network), etc. Brute force physical methods. Since this actually cuts off the signal, it may be a more realistic approach.
You may also want to try this through your wlan-router. First, disable data roaming on your iPhone. Then, let the iPhone be connected to the internet through your wlan network. Then, disconnect the gateway on your wlan router while your iPhone is still connected to the wlan network.
This depends on what failure modes you are trying to test.
I use Airplane mode as a first pass check to make sure an app submission isn't quickly rejected.
Other network failure handling checks might include:
3G only (no wifi).
WIFI only (in Airplane mode).
Pulling the power cord on the WIFI access point.
Pulling the network cable from the back of the WIFI access point after connecting to it (Reachability may falsely say yes).
Walking in and out of a basement
elevator (or other Faraday cage) in the middle of a transfer.
Driving between 2 cell towers during a data transfer.
Walking between 2 enabled WIFI access points between connection and data transfer.
Starting the app after more than 30 minutes of device inactivity (radios may be idle).
Running the app while another app (Safari, Mail) is downloading in the background.
etc.
I have a requirement to promote 3G/GPRS over WiFi connectivity in the iPhone application I am developing. Please let me know if this is possible and if yes, how?
The problem is when I have a WiFi network which is available and connected but not logged in using Captive Portal, I cannot use that WiFi network to perform the tasks which require internet connection. What i have noticed is Reachability API detects the available WiFi but I cannot use it as I am not logged in and so I am not connected to internet using this WiFi hotspot until I login. So I want to use 3G/GPRS to perform the tasks requiring internet connectivity.
iPhone's default behavior is it uses WiFi when its available and if not then only 3G/GPRS.
So please let me know if both 3G/GPRS and WiFi are available but I am connected to internet not using WiFi but 3G/GPRS how to use 3G/GRPS to perform the tasks requiring internet connectivity.
Regards,
Third-party applications don't get control of where their data comes from. About all you're going to be able to do is ask your users to turn wifi off while your application does its thing. If you need to get back onto wifi after doing the initial data transfer, you could make some clever use of the iOS 4 multitasking and local-notification APIs: when your application enters the background, it could start a background-task handler (using -beginBackgroundTaskWithExpirationHandler: in your app delegate's -applicationDidEnterBackground:) to wait for the wifi connection to become unavailable, do its thing with the cell network, then create a UILocalNotification to tell the user it's okay to turn wifi back on again. That way, the user could get the benefits of whatever your app does and still keep the connection they started out on.
If you are creating an app which needs to access certain network resource(s) to function, then you should just ping, or try to connect to those resources directly instead of just depending on reachability for the decision. If you can't ping your server, then have the app do the same thing it would if reachability reported zero connectivity (even though it may not be).
For security reasons, Apple doesn't allow developer to do such settings pro grammatically, despite you GPRS network connection to achieve some purposes.