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

后端 未结 6 1409
-上瘾入骨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: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.

提交回复
热议问题