Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if the user turned off cellular data for my app?

Although my app is usable without any internet connection, it may exchange data with a web server (in order to show some user statistics). So I advertise the app as "needs no internet connection". Some users subsequently have turned off cellular data for my app, which should be completely fine. But when my app tries to exchange data, these users are bugged with the "Cellular data is turned off for [App Name]." dialog.

This is an annoyance to them and I want to prevent these dialogs and simply skip the whole data exchange thing.

There is Apple's Reachability Sample Code.

But although I turned off WiFi for the whole device and cellular data for the app, Reachability confirms a positive internet connection. To be more specific, it reports

Reachability Flag Status: WR t------ networkStatusForFlags

no matter whether I activated cellular data or not. Of course, when cellular data is turned off, no internet connection is actually available, so the data exchange fails. But the user is presented with the cellular data dialog anyway.

Is there any way to detect whether a internet connection is available on iOS 7 and iOS 8, taking into account the cellular data setting for a specific app – all without bugging the user every time again with the cellular data dialog?

My app currently comes without any settings panel, so I want to avoid setting up a (second, in-app) switch "don't use cellular data". Also, I don't want to restrict data exchange to a WiFi connection since it's just a 2 KB of data per session which isn't a big thing for most users.

like image 849
C. S. Hammersmith Avatar asked Oct 14 '14 10:10

C. S. Hammersmith


1 Answers

I think the only supported way in iOS8 is to send a Ping to a known server and bug the user with the alert panel a few times. On iOS8, Apple displays the panel only twice, then skips it even if the app is restarted, maybe it will show up a day later again. (This is really bad news for ad-supported apps.)

Apple says (https://devforums.apple.com/message/1059332#1059332):

Another developer wrote in to DTS and thus I had a chance to investigate this in depth. Alas, the news is much as I expected: there is no supported way to detect that your app is in this state. Nor is there a way to make a "no user interaction" network connection, that is, request that the connection fail rather than present UI like this.

The following articles suggest ways to use ping:

http://www.splinter.com.au/how-to-ping-a-server-in-objective-c-iphone/

http://elbsolutions.com/projects/reachability-with-simpleping-wrapper/

like image 66
cat Avatar answered Nov 09 '22 00:11

cat