26

I know this question has been asked so many times. The answers say that this is not available in Xcode > 5.x. but I saw some apps that can use this(Go to Settings)(iOS7). Is there any way to do this? Is it available in Xcode 6? Facebook can detect both cellular data and wifi.

enter image description hereenter image description here

Car4p17
  • 45
  • 1
  • 6
MaappeaL
  • 514
  • 1
  • 8
  • 16
  • 2
    Those are both system messages, not app messages. As of iOS 8 you can only launch your app's own settings page. – rmaddy Sep 23 '14 at 06:32
  • Is there a way so I can show those system messages? And in iOS8, can i switch on the device's wifi/cellular data ? – MaappeaL Sep 23 '14 at 06:50

5 Answers5

85

As of iOS 8, it's possible to launch the Settings app that directly opens your Privacy app section in this way:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

In Swift:

if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.sharedApplication().openURL(settingsURL)
}

In Swift 3.0:

if let settingsURL = URL(string: UIApplicationOpenSettingsURLString + Bundle.main.bundleIdentifier!) {
    UIApplication.shared.openURL(settingsURL as URL)
}
Nikita Zernov
  • 5,465
  • 6
  • 39
  • 70
BalestraPatrick
  • 9,944
  • 4
  • 30
  • 43
  • 7
    Does anyone know how to open just Settings app not individual settings? Facebook does it. – Pei Jan 29 '15 at 16:53
  • 7
    @Pei Specify your app's bundle id in the url scheme: `[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@BundleID", UIApplicationOpenSettingsURLString]]];` – Aleksander Azizi Jul 27 '15 at 23:08
  • 1
    This is for swift code just in case you want: guard let bundleIdentifier: String = NSBundle.mainBundle().bundleIdentifier else { return } if let url = NSURL(string: UIApplicationOpenSettingsURLString + bundleIdentifier) { UIApplication.sharedApplication().openURL(url) } – ryutamaki Feb 11 '16 at 13:41
  • 1
    @AleksanderAzizi Specifying the app's bundle ID in the URL scheme doesn't seem to make a difference. – shim Sep 15 '16 at 20:25
7

1.- Add URL Types enter image description here

2.- Use:

Objective - C

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];

Swift

 UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=General")!)

3.- Other path find in this answer: iOS Launching Settings -> Restrictions URL Scheme

Community
  • 1
  • 1
Pablo
  • 119
  • 2
  • 4
3

This is not possible anymore in iOS 11, we can just open Settings. Here a Swift 4 code snippet:

if let url = URL(string:UIApplicationOpenSettingsURLString) {
   if UIApplication.shared.canOpenURL(url) {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}
HixField
  • 3,538
  • 1
  • 28
  • 54
chawki
  • 867
  • 1
  • 8
  • 13
3

iOS 13, Swift 5.0

Syntax for open settings changed [again] a tiny bit.

if let url = URL(string:UIApplication.openSettingsURLString) {
     if UIApplication.shared.canOpenURL(url) {
       UIApplication.shared.open(url, options: [:], completionHandler: nil)
     }
  }
user3069232
  • 8,587
  • 7
  • 46
  • 87
2

Alerts on your screenshots are system alerts. The first occurs when app wants to use internet and have a blocked cellular data for application (and Wifi is not connected). The second occurs when an application wants to use location services, and you have turned off wifi. It is not possible control the display of these alerts.

In iOS 8 (Xcode 6) is the ability to open the settings directly from the application. Please read this topics: How to open Settings programmatically like in Facebook app?

Opening the Settings app from another app

Community
  • 1
  • 1
pawel_d
  • 487
  • 5
  • 9
  • how can I show the first one ? like, if i tried to open url from my webview it means that I need to use the internet, will the alert show? can you give me an example ? – MaappeaL Sep 23 '14 at 07:41
  • Close your app. Turn off wifi. Go to settings->cellular -> in section "Use cellular data for:" find your app and disable it. Open your app. – pawel_d Sep 23 '14 at 07:47
  • if you download an app from apple store and the app is required to use the internet, is it automatically added to the list of apps that uses cellular data? My app is does not appear on the list, is it normal because it is just a testing ? – MaappeaL Sep 23 '14 at 08:46
  • I do not know if there is any flag indicating that this app requires internet access. I did a simple test. I created project with single view application and in AppDelegate didFinishLaunchingWithOptions added Line: [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.facebook.com"]] returningResponse:nil error:nil]; Turn wifi off and launch app. After that app appears on the list. – pawel_d Sep 23 '14 at 09:03