Accessing the Settings app from your app in iOS 8?

强颜欢笑 提交于 2019-11-27 00:54:05

问题


Is it possible to access the settings app from your own app via a button or whatever it may be in iOS 8. I heard that it got decrepitude in iOS 5, is that true? If not did the method change in iOS 8? If there is not other way to do this what would be the best way to work around it?


回答1:


As of iOS 8, it is possible to take a user from your app directly into the Settings app. They will be deep linked into your app's specific Settings page, but they can back out into the top level Settings screen.

If you're also supporting iOS 7 you'll need to check first if a specific string constant is present.

UPDATE:

If your deployment target is set to 8.0 or above, Xcode 6.3 will give you the following warning:

Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true

This is because the feature was available starting in 8.0, so this pointer will never be NULL. If your deployment target is 8.0+, just remove the if statement below.

if (&UIApplicationOpenSettingsURLString != NULL) {
    NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:appSettings];
} 



回答2:


Use UIApplicationOpenSettingsURLString.

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



回答3:


In Swift:

if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.sharedApplication().openURL(settingsURL)
}



回答4:


Swift 3 example:

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


来源:https://stackoverflow.com/questions/24229422/accessing-the-settings-app-from-your-app-in-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!