首页 > 移动平台 > 详细

iOS 8以上的设置的跳转

时间:2016-02-27 20:31:27      阅读:119      评论:0      收藏:0      [点我收藏+]

  iOS8以上的系统应用可以与设置进行深层的交互,用户可以根据APP的需要进行对应的权限的设置。

  现在大多数的APP依旧仅仅是弹出一个包含操作指令的警示窗口,如“进入设置>隐私>位置>APP”。其实在高版本的系统中可以直接弹出一个警示窗口,提示内容是自己的APP需要的权限,点击确定按钮可以直接跳到设置中的APP本身的权限设置界面。具体的操作方式及代码在下面。

  举例:

  一下是一个日历相关应用程序的警告代码,其中包含了为用户设置的选项。

  

func showEventsAcessDeniedAlert() {
let alertController = UIAlertController(title: "Sad Face Emoji!",
message: "The calendar permission was not authorized. Please enable it in Settings to continue.",
preferredStyle: .Alert)
let settingsAction = UIAlertAction(title: "Settings", style: .Default) { (alertAction) in
// THIS IS WHERE THE MAGIC HAPPENS!!!!
if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(appSettings)
}
}
alertController.addAction(settingsAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
presentViewController(alertController, animated: true, completion: nil)
}

  再次提醒,仅需要添加此代码到您的APP中就能实现与用户设置进行深层链接

  

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

  当用户点击打开设置的时候,他们就很方便的进入了这个界面

    技术分享

    只需添加这三行代码,就能在激活APP使用权限这一重要方面提高用户体验。让用户更改设置中的权限变得简单易行。同样,这也适用于许多其他的应用程序。

    技术分享

  文章内容参考自:本文由CocoaChina译者Kaming翻译,原文:iOS: You’re Doing Settings Wrong。

iOS 8以上的设置的跳转

原文:http://www.cnblogs.com/jw-blog/p/5223434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!