I can’t speak to
CTCellularPlanProvisioning
. I haven’t had a chance to look at that yet.
With regards
CTCellularData
, this is about the user’s ability to prevent apps from using WWAN (in Settings > {Cellular,Mobile} Data > SomeAppName). That does not require any entitlements. Here’s a snippet of code that shows it in action:
var cellularData: CTCellularData!
func setup() {
self.cellularData = CTCellularData()
self.cellularData.cellularDataRestrictionDidUpdateNotifier = { state in
let stateStr: String
switch state {
case .restrictedStateUnknown: stateStr = "unknown"
case .restricted: stateStr = "restricted"
case .notRestricted: stateStr = "not restricted"
}
NSLog("cellular data state: %@", stateStr)
}
}
If you then go into Settings and toggle access to WWAN, you see output like this:
2018-09-20 08:50:57… cellular data state: not restricted
2018-09-20 08:51:33… cellular data state: restricted
2018-09-20 08:51:42… cellular data state: not restricted
Some things to note:
Your app only shows up in Settings if it has used WWAN, so if you put this in a simple test app you’ll need to have that app run a request over WWAN before you start this test (which means adding some simple network code and running it with Wi-Fi disabled).
The notifier is only called when your app is running, so you see these callbacks when you switch back to the app from Settings.
I store my instance of
CTCellularData
in a property (cellularData
) to prevent it from being deallocated; if that happens the notifier never gets called.I built my test with Xcode 10.0 and run it on iOS 12.0.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"