2

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:

Jay
  • 21
  • 1
  • 2

2 Answers2

3

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: UIApplicationOpenSettingsURLString){
        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...

Community
  • 1
  • 1
Yash Bedi
  • 1,323
  • 17
  • 25
  • 1
    But Viber has done it. Turn off all internet connections and you will get an Alert with two buttons. Pressing the settings button it takes you to Cellular settings... – Ruzin Aug 28 '17 at 11:43
  • 1
    Updated the answer.. @Ruzin here's the answer to open specific settings in iOS: https://stackoverflow.com/a/33371820/4598318 – Yash Bedi Aug 29 '17 at 06:23
0

i am not sure about mobile data.

you can open app settings as follow

UIApplication.shared.openURL(URL(String:UIApplicationOpenSettingsURLString))
Sagar Bhut
  • 657
  • 6
  • 28