易采站长站为您分析IOS提醒用户重新授权打开定位功能的相关资料,需要的朋友可以参考下
iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置、通知、联系人、相机、日历以及健康等设置。
大多数应用程序仅仅是弹出一个包含操作指令的警示窗口,如“进入设置>隐私>位置>OUR_APP”。例如,推特的应用程序有一个更为精致和友好的指示对话框,所以我就把它当做一个例子来使用(可惜大多数应用程序都会有一个非常糟糕的版本)。
我现在以一个心情沮丧用户的身份写这个帖子,希望更多的iOS开发者能与用户设置建立直接的深层链接,尤其是操作起来也非常容易。
以下是一个日历相关的应用程序的警告提醒代码,其中包含了为用户进行设置的选项。我正试图在其中包含一个能将用户带入设置的选项。
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)
}
当用户拒绝了授权,这就更像Swarm应用程序了。
当用户点击“打开设置”时,他们就能很方便地进入这个界面。











