Detect wifi enabled (regardless of whether it's connected) - ios

For a GPS tracking app, recording location signals with WIFI turned on results in really imprecise data or data with gaps.
I've used the Reachability queries to detect if wifi is available prior to starting tracking. The problem is that if when that query is made the wifi is enabled but not connected to a network, it shows that the internet is not reachable via wifi, but that's not an indication of if the setting is disabled in the settings app. This means that if the user starts running and a connection is made mid-run, they'll get a location signal from the wifi instead of the GPS or cell network. Consequently the accuracy on those data points can be > 10 meters so I want to skip that point. The issue is that on wifi they'll have a large blank period where their signal wasn't recorded.
So how can I check if wifi is enabled but disconnected?
I've read all the other reachability discussions I could find but this seems to be the one gap with lots of responses incorrectly suggesting that reachability solves this out of the box.
...and I'm not going to require wifi - just alert them to the fact that it is enabled so at some point in their workout their location data might be lost (due to inaccuracy).

It's been quite a while since you asked, but I just came across this one.
It doesn't look like there is any way to do it if you want to obey Apple's rules. sysctl and ioctl won't work because there are no flags which will show you wether WiFi is enabled. For example the flags for "UP" and "RUNNING" will be the same if WiFi is disabled or WiFi is enabled but not connected.
Apple's own WiFi framework uses mach to directly communicate with the kernel and I doubt Apple would allows such code in the AppStore.

This IS possible, but the solution is obscure and ugly. The short answer is that if you see TWO interfaces with the name "awdl0" then WiFi is enabled, just one and it's disabled.
See Better way to detect WiFi enabled/disabled on iOS? for a more complete description and sample code.

Related

Working around the issue of being unable to acquire WiFi signal strength in iOS

I have an iOS app that I had intended on adding a feature which shows WiFi bars to show the user their WiFi signal strength while the app is in full screen. As I have learned recently, it is not possible to include a feature in an iOS app which allows you to show the signal strength of the connected wireless network since Apple does not allow this unless you sign up to register for Apple's NEHotspotHelper and this is not a normal use case for this API.
To work around this issue, is there some way of still showing the user that their WiFi connection isn't good? Could I measure the latency of the connection is some way to show an alert saying the connection is bad? Are there any other symptoms of a poor wireless connection that I could measure to still implement this function in my app?

APIs are not responding fast is APP is using Multipeer Connectivity framework

I am using Multipeer Connectivity Framework in my APP and its working absolutely fine but when APP is invoking any API or downloading any file from server then its delaying the response. Sometimes its failed and sometimes I am getting Time out error.
I have also checked "Network" status on xCode debug navigator and found that speed is going up and down instantly and never going beyond 6kb/s and sometimes its showing as 0 kb/s but when I disable Multipeer Connectivity then it works fine and speed going at 70kb/s too.
I have also noticed that if bluetooth is ON then its happening not with the Wifi.
Any suggestion would be really appreciable.
This is happening because when advertising, Multipeer always advertises on the wifi (there's no way to say bluetooth only). The way it advertises is by switching the wifi access mode into adhoc multiple times per second to find other peers, then switching back to AP mode (ie. resuming its connection to your wifi router). Doing this is highly disruptive to large transfers.
You have two options to fix this:
1) as soon as you can, after getting connected, call stopAdvertising(). This will stop the wifi mode from being constantly changed, and your throughput will resume at its normal rate. Warning: you cannot micro-manage this, because it takes up to 30 seconds after calling stopAdvertising() until it takes effect
2) switch from Multipeer to an alternative framework that allows you to specify bluetooth-only, and only use bluetooth. I wrote one called BluePeer which I use in my apps. It is unicast (not multicast) and supports roles like Client/Server (as well as role-less like Multipeer)

Significant location change doesn't work on Wifi only devices

Correct me if I'm wrong, I have two devices (iPhone), one with sim-card included and wifi connected, other doesn't have an active sim-card but connects to wifi. I was on train to test the significant location change on both devices, only the one with sim-card sent significant location change event. The one without sim-card didn't fire any event even though it still connected to Wifi.
Any link references are appreciated. IMO, does the significant location change only work with cellular data ?
I believe the significant location change updates location only when the phone swap from a cellular tower to another, so if it is not on the cellular network (without sim card) it can not detect that, and therefore cannot provide a position :)
From Apple doc:
The significant location change service is better suited for apps that want to get the user’s initial location and then only want to know when that location changes. This service requires the presence of cellular hardware and delivers events less frequently than the standard location services.
Source

iPhone - Disable Calling/Messaging Based on Bluetooth Signal

I am using an Arduino Uno microprocessor in conjunction with a bluetooth shield. This is irrelevant. What is important is that I am sending a bluetooth signal form this device. I want to make an app for my phone to immediately turn off, be disabled, or at least have text messaging and calling disabled. Basically, I want to put this device in a car and when my phone gets near, calling and messaging is disabled. I am okay if I need to keep my app running in the background. I cannot find any examples on the web, so any suggestions are deeply appreciated.
Apple's security mode doesn't allow for this. You will need to jailbreak it. How to do that is left for the reader.
Then, I would read up on CoreTelephony private methods:
https://github.com/EthanArbuckle/IOS-7-Headers/tree/master/Frameworks/CoreTelephony.framework

Is there a cellular data usage API in iOS 7?

iOS 7 introduced a new user configuration to disable cellular data for specific apps. It can be configured in "Settings"->"Cellular" and then scrolling down.
You'll find a switch for each installed app and can see how much cellular data it has consumed.
How can I programmatically test if the switch is turned on for my app? Is there an API for that? Can I determine how much data my app has used over cellular?
I'm not asking to get the values for all apps. I'm only interested in my apps usage.
There is no API to detect your download consumption or whether cellular is active for your app.
If your app tries to connect to a website, but cellular is turned off, then iOS may ask the user to turn cellular back on. I'm not exactly sure how that works, but it is probably similar to the iOS 6 "no network connection" alert that would pop up if there is no connection but an app tries to access the internet.
You can check if the current internet connection is over WiFi or Cellular, but if Cellular is disabled you will just be told that there is no network connection.
More details here: iOS Detect 3G or WiFi
You can't check if the cellular data switch is turned on.
The closest thing is that you can check if a specific host is reachable over cellular connection using the SCNetworkReachability kSCNetworkReachabilityFlagsIsWWAN flag.
Additionally, you can enable/disable cellular data for specific connections using the NSURLRequest allowsCellularAccess property.
Reference: https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/Platform-SpecificNetworkingTechnologies/Platform-SpecificNetworkingTechnologies.html
This answer suggests how data usage can be measured system-wide: iPhone Data Usage Tracking/Monitoring

Resources