Opening the Settings app from another app

前端 未结 17 2194
傲寒
傲寒 2020-11-22 01:37

Okay, I know that there are many question about it, but they are all from many time ago.

So. I know that it is possible because the Map app does it.

In the M

相关标签:
17条回答
  • 2020-11-22 02:07

    You can use the below code for it.

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    
    0 讨论(0)
  • 2020-11-22 02:07

    Tested with iOS 10. Working

    NSArray* urlStrings = @[@"prefs:root=WIFI", @"App-Prefs:root=WIFI"];
    for(NSString* urlString in urlStrings){
    NSURL* url = [NSURL URLWithString:urlString];
    if([[UIApplication sharedApplication] canOpenURL:url]){
        [[UIApplication sharedApplication] openURL:url];
        break;
    }
    }
    

    Happy Coding :)

    0 讨论(0)
  • 2020-11-22 02:09

    iOS 10 update

    Apple changed the method to open async on the main thread. However, from now it is only possible to open the app settings in native settings.

    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];

    iOS 9 update

    It is now possible to go directly to sub-settings menu. However, a URL scheme has to be created. It can be done using two ways:

    1. XCode - You will find it in Target, Info, URL Scheme. Then, just type prefs.
    2. Directly adding to *-Info.plist. Add the following: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>prefs</string> </array> </dict> </array>

    Then the code:

    Swift

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

    Objective-c

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

    0 讨论(0)
  • 2020-11-22 02:12

    YES!! you can launch Device Settings screen, I have tested on iOS 9.2

    Step 1. we need to add URL schemes

    Go to Project settings --> Info --> URL Types --> Add New URL Schemes

    Step 2. Launch Settings programmatically Thanks to @davidcann

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
    

    Also we can launch sub-screens like Music, Location etc. as well by just using proper name

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

    See this full name list here shared by Henri Normak


    Update:

    As per the comment everyone wants to know what happens after this change to my application submission status?

    So YES!! I got successful update submission and application is available on store without any complain.

    Just to confirm, I Just downloaded this morning and disabled Location services, and then started the app, which asked me for location permission and then my alert popup was there to send me on settings -> location services page --> Enabled --> That's it!!

    ![NOTICE: Your app might be rejected ... even if it's approved it can be rejected in future version if you use this method...]4

    0 讨论(0)
  • 2020-11-22 02:12

    UIApplicationOpenSettingsURLString this will only work if you have previously allowed for any permission. For example Location, Photo, Contact, Push notification access. So if you have not such permission(s) from the user:

    If iOS 10 or above,

    It will open the Settings but then crash it. The reason, there's nothing in settings for your app.

    Below code will open your application settings inside the iOS Setting.

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
    

    Due to device unavailability, I couldn't check this on iOS < 10.

    Also, I could find below code from some gist and it works fine on iOS 10 as well. But I am not sure if this will approve by Apple review team or not.

    https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f

    0 讨论(0)
  • 2020-11-22 02:14

    As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString see Apple's Documentation.

    Example:

    Swift 4.2

    UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
    

    In Swift 3:

    UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
    

    In Swift 2:

    UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
    

    In Objective-C

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

    Prior to iOS 8:

    You can not. As you said this has been covered many times and that pop up asking you to turn on location services is supplied by Apple and not by the App itself. That is why it is able to the open the settings application.

    Here are a few related questions & articles:

    is it possible to open Settings App using openURL?

    Programmatically opening the settings app (iPhone)

    How can I open the Settings app when the user presses a button?

    iPhone: Opening Application Preferences Panel From App

    Open UIPickerView by clicking on an entry in the app's preferences - How to?

    Open the Settings app?

    iOS: You’re Doing Settings Wrong

    0 讨论(0)
提交回复
热议问题