首页 文章

如何在用户按下按钮时打开“设置”应用程序?

提问于
浏览
9

根据我的理解,使用这样的代码:

NSURL* appUrl = [NSURL URLWithString: @"URL"];
[[UIApplication sharedApplication] openURL:appUrl];

当用户说按下按钮时,我可以打开 Map ,YouTube,Safari,邮件,iTunes和App Store .

但我想知道是否可以使用此方法打开“设置”应用 .

基本上,当用户第一次打开我的应用程序时,我想要弹出一个UIAlertView,让用户知道他们可以根据需要更改特定设置,然后按OK或者按设置将他们带到设置应用程序 .

我知道Apple在某些情况下这样做,但是开发人员可以这样做吗?

6 回答

  • 16

    根据@ bnduati的回答,在iOS 8中,您可以使用以下代码在设置应用中打开应用程序的设置:

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

    老答案:

    从iOS 5.1到iOS 7,无法从其他应用程序打开设置应用程序 .

    您可能需要调查this framework以提供应用内设置 .

    还有很多其他问题可以讨论这个主题:

    iPhone - how to put Settings bundle seen through System Settings App into your own App?

    Launch iPhone setting screen from Application?

    How to send a user to the main iPhone Settings screen from within your iPhone App

  • 9

    在iOS 8及更高版本中,您可以通过以下方式将用户发送到应用程序的设置:

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

    您可以在iOS 5.0及更高版本上使用它:

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

    我不知道这是否可行,但有一个问题是用户需要导航回你的应用程序 . 您可以改为拥有自己的首选项视图,该视图可以使用NSUserDefaults写入首选项应用程序将使用的同一文件 .

    [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

    [[NSUserDefaults standardUserDefaults] stringForKey:key]

  • 3

    Swift Syntax:

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

    斯威夫特3

    private func showAlertPrivacy() {
        let alertController = UIAlertController(title: nil, message: "messagePrivacy", preferredStyle: .alert)
        let alertNo = UIAlertAction(title: "No", style: .default) { (_) in
    
        }
        alertController.addAction(alertNo)
    
        let alertSetting = UIAlertAction(title: "Settings", style: .default) { (_) in
    
            UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!, options: [:], completionHandler: { (_) in
    
            })
        }
        alertController.addAction(alertSetting)
    
        present(alertController, animated: true) { 
    
        }
    }
    

相关问题