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

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

提交回复
热议问题