Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get through Mobile Data Settings Programmatically in iOS Swift 3

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:

like image 828
Jay Avatar asked Dec 21 '25 07:12

Jay


2 Answers

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...

like image 69
Yash Bedi Avatar answered Dec 23 '25 20:12

Yash Bedi


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)")
        })
    }
}
like image 44
Ali Raza Avatar answered Dec 23 '25 20:12

Ali Raza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!