I am creating a new Traveling Application in iOS, this application is highly dependent on Maps and will include two Maps.
- My first Map will work when the user has a strong Network Signal (Apple Maps).
- My second Map will be used when their isn't any Network or really Low signal (Offline MapBox).
Why do I have two different maps in one Application? My Application is a Direction App, so when the user has really low network or none it will go to the offline Map MapBox
. Also the Apple Maps will have Yelp integration and not the offline Map MapBox
.
So my Question: How can I detect the network signal in WiFi, 4G Lte, and 3G.
My original thought was to time the download of a file, and see how long it takes:
Note, this measures the speed including the latency of starting the connection. You could alternatively initialize
startTime
indidReceiveResponse
, if you wanted to factor out that initial latency.Having done that, in retrospect, I don't like spending time or bandwidth downloading something that has no practical benefit to the app. So, as an alternative, I might suggest a far more pragmatic approach: Why don't you just try to open a
MKMapView
and see how long it takes to finish downloading the map? If it fails or if it takes more than a certain amount of time, then switch to your offline map. Again, there is quite a bit of variability here (not only because network bandwidth and latency, but also because some map images appear to be cached), so make sure to set akMaximumElapsedTime
to be large enough to handle all the reasonable permutations of a successful connection (i.e., don't be too aggressive in using a low value).To do this, just make sure to set your view controller to be the
delegate
of theMKMapView
. And then you can do:For Swift
I believe a google search will help.
Look out for the following thread on StackOverflow—
iOS wifi scan, signal strength
iPhone signal strength
So, I don't think you can still do this without using private APIs.