So I've done a lot of research and I haven't quite found the answer I have been looking for...
I want to make it so that, if cellular data is turned off for my app in particular, the app doesn't work or at least make it so a few buttons are hidden.
I have reachability put in place so that if there is no internet connection, the app does not run. However, if the user is connected to the internet but has cellular data turned off for my app, and they are not connected to wifi, then the app runs (which I do not want it to do).
Any help would be highly appreciated!
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With