How to jump to system setting's location service on iOS10?

后端 未结 6 1410
-上瘾入骨i
-上瘾入骨i 2021-01-05 09:59

Before I asked this question I had try:

  1. Use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"prefs:root=Privacy&path=LOCATION\"]];<
相关标签:
6条回答
  • 2021-01-05 10:08

    This works for me. iOS7 ~ iOS11

    But if you are uing the iOS11, you can only jump to the app's setting page

    0 讨论(0)
  • 2021-01-05 10:19

    Thanks to this guy. I figure out this URL Scheme Prefs:root=Privacy&path=LOCATION is only available in Today Widget, but no use in containing app.

    In Today Widget, you can try this:

    [self.extensionContext openURL:[NSURL URLWithString:@"Prefs:root=Privacy&path=LOCATION"] completionHandler:nil];
    

    More about system URL Schemes, you can see here.

    This all I got. Hope it will help you.

    0 讨论(0)
  • 2021-01-05 10:22

    Note:I use this method for a long time and everyting goes well,but today(2018-9-14),I had been rejected.

    Here is my previous answer,do not use this method forever:

    CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
    if (systemVersion < 10) {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];
    }else{
     [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]
                                              options:[NSDictionary dictionary]
                                    completionHandler:nil];
    }
    

    Now I use this way:

    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
    
    0 讨论(0)
  • 2021-01-05 10:28

    You can also open your app's setting center by opening"App-Prefs:root=your app bundle id". This will be easy for user to change setting for your app.

    0 讨论(0)
  • 2021-01-05 10:30

    Note :- this solution will not be useful for ios10 onwards

    Dont forget to add URL schemes :-

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

    after that Use this url :-

    let settingUrl =  URL(string: "App-Prefs:root=Privacy&path=LOCATION")
    

    And open using :-

          if #available(iOS 10.0, *) {
             UIApplication.shared.open(settingUrl) {
                    (isOpen:Bool) in
                    if !isOpen {
                        debugPrint("Error opening:\(settingUrl.absoluteString)")
                        // show error
                    }
                }
          }else{ 
             if UIApplication.shared.canOpenURL(settingUrl) {
                UIApplication.shared.open(settingUrl, completionHandler: { (success) in
                print("Settings opened: \(success)") // Prints true
    
               })
             }
          }
    

    Enjoy :)..this worked for me.

    0 讨论(0)
  • 2021-01-05 10:31

    For some time now, apps have only been permitted to open their own settings pane in the settings app. There have been various settings URLs that have worked in the past, but recently Apple has been rejecting apps that use these URLS.

    You can open your own application's settings:

    if let url = URL(string:UIApplicationOpenSettingsURLString) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
    

    Or in Objective-C

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if (url != nil) {
        [[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];
    }
    

    If you are targeting version of iOS earlier than 10 then you may prefer to use the older, deprecated, but still functional method:

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if (url != nil) {
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] openURL:url];
    #pragma clang diagnostic pop
    }
    
    0 讨论(0)
提交回复
热议问题