简体   繁体   中英

iOS : Open my App Specific Location Settings

I have a requirement to Open up my iOS App Specific Location Settings. I am aware that we can Open the General Location Settings through the below:

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

I have two Questions:

  1. Is the above valid and the right as per Apple guidelines (or) should we just Open up the Settings App and allow the user to change the settings?

  2. My requirement is to open my App's Specific Location Settings - the one that shows "Always", "While Using App", "Never", so that the user can modify the same. Is this possible

Thanks in advance.

For Swift 3 and above: Plus the Code also checks the ios version and does the job for all versions.

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 ie in plist file Here are some url's Cocoa keys for iOS 10 , Cocoa Keys from developer.apple

This will take the user to the app specific settings screen where location, camera, notifications and any other permissions that were requested by the app are listed for the user to toggle.

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM