好吧,我知道关于它有很多问题,但它们都是很久以前的事了。

所以。我知道这是可能的,因为地图应用程序做到了。

在地图应用程序中,如果我关闭这个应用程序的本地化,它会给我发送一条消息,如果我按ok,“设置应用程序”就会打开。 我的问题是,这怎么可能呢? 如何从我自己的应用程序打开“设置应用程序”?

基本上我需要做同样的事情,如果用户关闭了我的应用程序的位置,那么我就会给他显示一条信息,上面写着将打开“设置应用程序”


正如Karan Dua提到的,这现在可以在iOS8中使用UIApplicationOpenSettingsURLString,参见苹果的文档。

例子:

斯威夫特4.2

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

在Swift 3中:

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

在Swift 2中:

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

在objective - c中

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

iOS 8之前:

你不能。正如你所说,这已经被报道了很多次,弹出窗口要求你打开位置服务是由苹果公司提供的,而不是由应用程序本身。这就是为什么它能够打开设置应用程序。

以下是一些相关的问题和文章:

是否可以使用openURL打开设置应用程序?

以编程方式打开设置应用程序(iPhone)

当用户按下按钮时,如何打开设置应用程序?

iPhone:从应用程序打开应用程序首选项面板

通过单击应用程序首选项中的一个条目打开UIPickerView -如何?

打开设置应用程序?

iOS:你的设置是错误的


你可以在iOS 5.0及更高版本上使用这个:这个不再有效。

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

来自@Yatheeshaless的回答:

你可以在iOS8中以编程方式打开设置应用程序,但在早期版本的iOS中不能。

迅速:

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

斯威夫特4:

if let url = NSURL(string: UIApplicationOpenSettingsURLString) as URL? {
    UIApplication.shared.openURL(url)
}

Swift 4.2 (BETA):

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

objective - c:

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

是的! !你可以启动设备设置界面,我已经在iOS 9.2上测试过了

步骤1。我们需要添加URL方案

去项目设置——>信息——> URL类型——>添加新的URL方案

步骤2。通过编程启动设置感谢@davidcann

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

此外,我们还可以通过使用适当的名称来启动音乐、位置等子屏幕

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

请看亨利·诺马克分享的完整名单


更新:

根据评论,每个人都想知道我的申请提交状态改变后会发生什么?

是的! !我获得了成功的更新提交和应用程序可在商店没有任何抱怨。

确认一下, 我今天早上刚下载并禁用了位置服务,然后启动了应用程序,它要求我获得位置权限,然后我的警报弹出在那里发送给我设置->位置服务页面->启用->就是这样!!

(注意:! 你的应用可能会被拒绝……如果你使用这种方法,即使它被批准了,在将来的版本中也可能会被拒绝


iOS 10更新

苹果将该方法更改为在主线程上打开async。但是,从现在开始,只能在本机设置中打开应用程序设置。

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

iOS 9更新

现在可以直接进入子设置菜单。但是,需要创建URL方案。有两种方法:

XCode -你会在目标,信息,URL方案中找到它。然后,输入prefs。 直接添加到*-Info.plist。增加如下内容: <键> CFBundleURLTypes关键> < / < >数组 < dict > <键> CFBundleTypeRole关键> < / <字符串>编辑字符串> < / <键> CFBundleURLSchemes关键> < / < >数组 <字符串>首选项> < /字符串 > < /数组 < / dict > > < /数组

然后代码:

斯威夫特

UIApplication.sharedApplication () .openURL (NSURL(弦:“首选项:根=一般路径=键盘”)!)

objective - c

[eapplication sharedApplication] openURL:[NSURL优先字符串:


您可以使用下面的代码。

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

把这个加到你的课上,

 public class func showSettingsAlert(title:String,message:String,onVC viewController:UIViewController,onCancel:(()->())?){
            YourClass.show2ButtonsAlert(onVC: viewController, title: title, message: message, button1Title: "Settings", button2Title: "Cancel", onButton1Click: {
                if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString){
                    UIApplication.sharedApplication().openURL(settingsURL)
                }
                }, onButton2Click: {
                    onCancel?()
            })
        }

 public class func show2ButtonsAlert(onVC viewController:UIViewController,title:String,message:String,button1Title:String,button2Title:String,onButton1Click:(()->())?,onButton2Click:(()->())?){
            dispatch_async(dispatch_get_main_queue()) {
                let alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title: button1Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton1Click?()
                }))

                alert.addAction(UIAlertAction(title: button2Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton2Click?()
                }))

                viewController.presentViewController(alert, animated: true, completion: nil)
            }
        }

像这样调用,

YourClass.showSettingsAlert("App would like to access camera", message: "App would like to access camera desc", onVC: fromViewController, onCancel: {
  print("canceled")
})

UIApplicationOpenSettingsURLString这只会在你之前允许任何权限的情况下起作用。例如位置,照片,联系人,推送通知访问。因此,如果您没有用户的此类权限:

如果是iOS 10或以上版本,

它会打开设置,但随后会崩溃。原因是,你的应用设置里什么都没有。

下面的代码将在iOS设置中打开你的应用程序设置。

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

由于设备不可用,我无法在iOS < 10上检查这一点。

此外,我可以从一些要点中找到下面的代码,它在iOS 10上也能正常工作。但我不确定这是否会得到苹果审查团队的批准。

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


斯威夫特 您可以使用以下功能打开蓝牙页面设置App

func openSettingsApp(){
    if let settings = NSURL(string: "prefs:root=Bluetooth") {
        UIApplication.sharedApplication().openURL(settings)
    }
}

同样,这不会打开应用程序的设置。这将打开蓝牙设置应用程序,因为这是深度链接到蓝牙。


在Swift 3 / iOS 10+中看起来是这样的

if let url = URL(string: "App-Prefs:root=LOCATION_SERVICES") {
    UIApplication.shared.open(url, completionHandler: .none)
}

在Swift 3中,我所需要的是这个(例如重定向到我的应用程序通知):

if let url = URL(string: "App-Prefs:root=NOTIFICATIONS_ID&path=your app bundleID") {
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, completionHandler: .none)
    } else {
        // Fallback on earlier versions
    }
}

来源:phynet gist。

这只适用于我设置在后台。它会将你重定向到你的应用通知设置但如果设置没有在后台运行它会将你重定向到一般的通知设置。


斯威夫特3:

guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
  UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
  // Fallback on earlier versions
  UIApplication.shared.openURL(url)
}

在iOS 10上测试。工作

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;
}
}

快乐编码:)


斯威夫特4.0

'openURL'在iOS 10.0中已弃用:请使用 openURL:选项:completionHandler:不是

UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)

斯威夫特4

我更喜欢以更安全的方式打开设置,

if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {

    UIApplication.shared.open(settingUrl)
}
else {
    print("Setting URL invalid")
}

添加到接受的答案:(来自苹果开发者文档)当你打开这个字符串(openSettingsURLString)构建的URL时,系统启动设置应用程序,并显示应用程序的自定义设置(如果有的话)。如果你想打开应用的设置,创建你自己的settings。bundle。


似乎你可以使用prefs:<area> URL来打开设置并进入特定的区域。苹果可能会改变这些,破坏你的应用程序,所以一定要先检查你是否能打开它们。

从这篇文章中,他们列出了iOS 13.1的一些功能:

设置网址

iCloud

iCloud:控制台:根=城堡 iCloud Backup: prefs:root=CASTLE&path= Backup

无线收音机

wi - fi:控制台:根= WIFI 蓝牙:控制台:根=蓝牙 细胞:控制台:根= MOBILE_DATA_SETTINGS_ID

个人热点

个人热点:prefs:root=INTERNET_TETHERING 个人热点⇾家庭共享:prefs:root=INTERNET_TETHERING&path=家庭%20Sharing 个人热点⇾Wi-Fi密码:prefs:root=INTERNET_TETHERING&path=Wi-Fi%20Password

VPN

VPN:控制台:根=一般路径= VPN

通知

通知:控制台:根= NOTIFICATIONS_ID 通知⇾Siri建议:prefs:root=NOTIFICATIONS_ID&path=Siri%20建议

听起来

声音:控制台:根=声音 铃声:控制台:根= Sounds&path =铃声

请勿打扰

请勿打扰:prefs:root=DO_NOT_DISTURB 请勿打扰⇾允许来自:prefs:root=DO_NOT_DISTURB&path=允许%20Calls%20From

屏幕时间

屏幕时间:prefs:root=SCREEN_TIME 屏幕时间⇾停机时间:prefs:root=SCREEN_TIME&path=停机时间 屏幕时间⇾应用程序限制:prefs:root=SCREEN_TIME&path=APP_LIMITS 屏幕时间⇾Always Allowed: prefs:root=SCREEN_TIME&path=ALWAYS_ALLOWED

一般

General: prefs:root=General General ⇾ About: prefs:root=General&path=About General ⇾ Software Update: prefs:root=General&path=SOFTWARE_UPDATE_LINK General ⇾ CarPlay: prefs:root=General&path=CARPLAY General ⇾ Background App Refresh: prefs:root=General&path=AUTO_CONTENT_DOWNLOAD General ⇾ Multitasking (iPad-only): prefs:root=General&path=MULTITASKING General ⇾ Date & Time: prefs:root=General&path=DATE_AND_TIME General ⇾ Keyboard: prefs:root=General&path=Keyboard General ⇾ Keyboard ⇾ Keyboards: prefs:root=General&path=Keyboard/KEYBOARDS General ⇾ Keyboard ⇾ Hardware Keyboard: prefs:root=General&path=Keyboard/Hardware%20Keyboard General ⇾ Keyboard ⇾ Text Replacement: prefs:root=General&path=Keyboard/USER_DICTIONARY General ⇾ Keyboard ⇾ One Handed Keyboard: prefs:root=General&path=Keyboard/ReachableKeyboard General ⇾ Language & Region: prefs:root=General&path=INTERNATIONAL General ⇾ Dictionary: prefs:root=General&path=DICTIONARY General ⇾ Profiles: prefs:root=General&path=ManagedConfigurationList General ⇾ Reset: prefs:root=General&path=Reset

控制中心

ControlCenter: prefs:root=ControlCenter 控制中心⇾自定义控件:prefs:root=ControlCenter&path=CUSTOMIZE_CONTROLS

显示

显示:控制台:根=显示 显示⇾Auto Lock: prefs:root= Display &path=AUTOLOCK 显示⇾文本大小:prefs:root=DISPLAY&path=TEXT_SIZE

可访问性

可访问性:控制台:根=可访问性

壁纸

壁纸:控制台:根=壁纸

Siri

Siri: prefs root = Siri

苹果的铅笔

苹果铅笔(仅限ipad): prefs:root=铅笔

面对ID

Face ID: prefs:root=PASSCODE

紧急求救信号

紧急SOS: prefs:root=EMERGENCY_SOS

电池

电池:控制台:根= BATTERY_USAGE Battery⇾Battery Health(仅限iphone): prefs:root=BATTERY_USAGE&path=BATTERY_HEALTH

隐私

Privacy: prefs:root=Privacy Privacy ⇾ Location Services: prefs:root=Privacy&path=LOCATION Privacy ⇾ Contacts: prefs:root=Privacy&path=CONTACTS Privacy ⇾ Calendars: prefs:root=Privacy&path=CALENDARS Privacy ⇾ Reminders: prefs:root=Privacy&path=REMINDERS Privacy ⇾ Photos: prefs:root=Privacy&path=PHOTOS Privacy ⇾ Microphone: prefs:root=Privacy&path=MICROPHONE Privacy ⇾ Speech Recognition: prefs:root=Privacy&path=SPEECH_RECOGNITION Privacy ⇾ Camera: prefs:root=Privacy&path=CAMERA Privacy ⇾ Motion: prefs:root=Privacy&path=MOTION\

应用程序商店

App Store: prefs:root= Store App Store⇾App Downloads: prefs:root= Store &path=App%20Downloads App Store⇾视频自动播放:prefs:root= Store &path=视频%20Autoplay

钱包

钱包:控制台:根=存折

密码及帐号

密码和帐户:prefs:root=ACCOUNTS_AND_PASSWORDS 密码和帐户⇾获取新数据:prefs:root=ACCOUNTS_AND_PASSWORDS&path=FETCH_NEW_DATA 密码和帐号⇾添加帐号:prefs:root=ACCOUNTS_AND_PASSWORDS&path=ADD_ACCOUNT

Mail

Mail: prefs:root=MAIL Mail ⇾ Preview: prefs:root=MAIL&path=Preview Mail ⇾ Swipe Options: prefs:root=MAIL&path=Swipe%20Options Mail ⇾ Notifications: prefs:root=MAIL&path=NOTIFICATIONS Mail ⇾ Blocked: prefs:root=MAIL&path=Blocked Mail ⇾ Muted Thread Action: prefs:root=MAIL&path=Muted%20Thread%20Action Mail ⇾ Blocked Sender Options: prefs:root=MAIL&path=Blocked%20Sender%20Options Mail ⇾ Mark Addresses: prefs:root=MAIL&path=Mark%20Addresses Mail ⇾ Increase Quote Level: prefs:root=MAIL&path=Increase%20Quote%20Level Mail ⇾ Include Attachments with Replies: prefs:root=MAIL&path=Include%20Attachments%20with%20Replies Mail ⇾ Signature: prefs:root=MAIL&path=Signature Mail ⇾ Default Account: prefs:root=MAIL&path=Default%20Account

联系人

联系人:控制台:根=联系人

日历

日历:控制台:根=日历 日历⇾备用日历:prefs:root=CALENDAR&path=备用%20日历 日历⇾同步:prefs:root=CALENDAR&path=同步 日历⇾默认警报次数:prefs:root= Calendar &path=默认%20Alert%20次 日历⇾默认日历:prefs:root=CALENDAR&path=默认%20Calendar

笔记

Notes: prefs:root=NOTES Notes ⇾ Default Account: prefs:root=NOTES&path=Default%20Account Notes ⇾ Password: prefs:root=NOTES&path=Password Notes ⇾ Sort Notes By: prefs:root=NOTES&path=Sort%20Notes%20By Notes ⇾ New Notes Start With: prefs:root=NOTES&path=New%20Notes%20Start%20With Notes ⇾ Sort Checked Items: prefs:root=NOTES&path=Sort%20Checked%20Items Notes ⇾ Lines & Grids: prefs:root=NOTES&path=Lines%20%26%20Grids Notes ⇾ Access Notes from Lock Screen: prefs:root=NOTES&path=Access%20Notes%20from%20Lock%20Screen

提醒

提醒:控制台:根=提醒 提醒⇾默认列表:prefs:root=REMINDERS&path=DEFAULT_LIST

语音备忘录

语音备忘录:prefs:root=VOICE_MEMOS

电话

电话:控制台:根=电话

消息

消息:控制台:根=消息

FaceTime

FaceTime:控制台:根= FaceTime

Maps

地图:控制台:根=地图 地图⇾驾驶和导航:prefs:root=MAPS&path=驾驶%20%26%20Navigation Maps⇾Transit: prefs:root=MAPS&path=Transit

指南针

指南针:控制台:根=指南针

测量

措施:控制台:根=措施

Safari

Safari: prefs:root=SAFARI Safari ⇾ Content Blockers: prefs:root=SAFARI&path=Content%20Blockers Safari ⇾ Downloads: prefs:root=SAFARI&path=DOWNLOADS Safari ⇾ Close Tabs: prefs:root=SAFARI&path=Close%20Tabs Safari ⇾ Clear History and Data: prefs:root=SAFARI&path=CLEAR_HISTORY_AND_DATA Safari ⇾ Page Zoom: prefs:root=SAFARI&path=Page%20Zoom Safari ⇾ Request Desktop Website: prefs:root=SAFARI&path=Request%20Desktop%20Website Safari ⇾ Reader: prefs:root=SAFARI&path=Reader Safari ⇾ Camera: prefs:root=SAFARI&path=Camera Safari ⇾ Microphone: prefs:root=SAFARI&path=Microphone Safari ⇾ Location: prefs:root=SAFARI&path=Location Safari ⇾ Advanced: prefs:root=SAFARI&path=ADVANCED

News

新闻:控制台:根=新闻

健康

健康:控制台:根=健康

快捷键

快捷键:控制台:根=捷径

音乐

音乐:控制台:根=音乐 音乐⇾CellularData: prefs:root=MUSIC&path=com.apple.Music:CellularData 音乐⇾优化存储:prefs:root= Music &path=com.apple.Music:优化存储 音乐⇾EQ: prefs:root= Music &path=com.apple.Music:EQ 音乐⇾音量限制:prefs:root=MUSIC&path=com.apple.Music:VolumeLimit

TV

设置⇾TV: prefs:root=TVAPP

照片

照片:控制台:根=照片

相机

相机:控制台:根=相机 摄像头⇾录制视频:prefs:root= Camera &path=录制%20Video 相机⇾记录慢镜头:prefs:root= Camera &path=记录%20慢镜头

书:控制台:根= IBOOKS

游戏中心

Game Center: prefs:root=GAMECENTER


由于openURL(_::)在iOS 10.0之后已被弃用,请使用open(_:options:completionHandler:)代替。

if let settingsUrl = URL(string: UIApplication.openSettingsURLString)  {
        UIApplication.shared.open(settingsUrl, options: [:]) { completed in
             if !completed {
                 print("Failed opening")
             }
        }
}