How do I know if cellular access for my iOS app is disabled?
So I found this on the apple dev forums from an Apple engineer (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. If these limitations are causing problems for your app, I
encourage you to file a bug describing your specific requirements.
https://developer.apple.com/bug-reporting/
So it looks like it is not possible to detect if cellular data for your app has been turned off.
Edit
I filed a radar for this requesting that it be added. I just got this notification in my radar
We believe this issue has been addressed in the latest iOS 9 beta.
I looked through the API diffs, but so far I can't find the new API.
Checking if Cellular Data has been turned off
I had a similar problem and found this solution. Hopefully it helps.
func isCellularRestricted() {
let cellState = CTCellularData.init()
cellState.cellularDataRestrictionDidUpdateNotifier = { (dataRestrictedState) in
if dataRestrictedState == CTCellularDataRestrictedState.restricted { // State has changed
// your app doesn't have cellular data
} else if dataRestrictedState == CTCellularDataRestrictedState.notRestricted {
// your app does have cellular data
}
}
}
This is the function I implemented in my app delegate (called from didFinishLaunchingWithOptions). It gets called everytime user changes cellular data for your app and only for your app. If user allows cellular data for your app and has turned off cellular data in iOS, this will still return notRestricted.
In my case I made a constant which I set to true/false, depending if cellular data is allowed.
I found the answer somewhere on SO but I cannot find the link.
EDIT (found link): How do I know if cellular access for my iOS app is disabled?
How to tell if the user turned off cellular data for my app?
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/
Related Topics
Using Nsuserdefaults with Xcode 8 and iOS 10
How to Add Images for Different Screen Size from Assets.Xcassets in Xcode 8
How to Rotate Orientation Programmatically in Swift
Trying to Set Only Time in Uidatepicker in Swift 2.0
Cannot Assign a Value of Type "String" to Type "Uilabel" in Swift
Swift: Can't Get Nsdate Dateformatter Right
Realmswift: Convert Results to Swift Array
iOS UI Testing on an Isolated View
What Are the Device-Width CSS Viewport Sizes of the Iphone6 and iPhone 6 Plus
Uitableview Checkmark Only One Row at a Time
Launch Apple Mail App from Within My Own App
What Does Deployment Target Mean
Why the Skstorereviewcontroller Does Not Let Me Submit a Review
Type 'Viewcontroller' Does Not Conform to Protocol 'Uitableviewdatasource'
Swift Error:Signal Sigabrt How to Solve It
iPhone In-App Purchase Store Kit Error -1003 "Cannot Connect to Itunes Store"
How to Prevent Uinavigationbar from Covering Top of View in iOS 7