i am trying to access the mobile data/ cellular data setting page which lists all the apps that have access to mobile/cellular data or internet.
I tried the below code:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let currentCell = featuresTable.cellForRow(at: indexPath)! as! HomeTableViewCell
if(currentCell.featureName!.text == "Internet Permissions")
{
// The code to enter the mobile data settings
let url = URL(string: "App-Prefs:root=MOBILEDATA")
let app = UIApplication.shared
app.openURL(url!)
}
}
Here the Output i want:
It is possible.! but the standard approach is to always open your App Setting Screen which is done by below code.All the Apps like Uber,Facebook etc use the below approach. the below code is written in
Swift 3 Plus the Code also checks the ios version and does the job for all versions, Also a little bit Explanatory
if let url = URL(string: UIApplication.openSettingsURLString){
if #available(iOS 10.0, *){
UIApplication.shared.open(url, completionHandler: nil)
print("\n--- in ios 10 ")
} else{
UIApplication.shared.openURL(url)
print("\n--- in ios other than 10 ")
}
}
UIApplicationOpenSettingsURLString : Basically opens your app's settings, Also It shows all the Services being used by app Including Locations Services,Mobile Data, Photo Library etc...
Now to add Cocoa Keys to your app i.e. in plist file Here are some url's Cocoa keys for iOS 10, Cocoa Keys from developer.apple
Hope it helps...
Solution for iOS 17.2.
if let url = URL(string:"App-prefs:MOBILE_DATA_SETTINGS_ID") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, completionHandler: { (success) in
print("Settings opened: \(success)")
})
}
}
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