iOS权限警报问题
我认为: 使用调用选择器为UIApplicationIDBecMeactiveNotification创建观察者 按顺序向用户请求权限:使用相机、定位和接收推送通知。 该视图有三个UIButton,其状态取决于每个权限状态,如果拒绝任何权限,则这些UIButton会将用户导航到设置 点击表示具有拒绝状态的权限的按钮可将用户导航到设置 一旦使用观察者操作隐藏每个警报,将触发下一个警报,并更新所有按钮状态以反映任何更改 一旦授予了所有权限,它将推送下一个视图以及注册/导入流的其余部分 问题是:在某些设备上,当从已删除并重新安装的干净状态应用程序运行应用程序时,默认情况下,位置和通知的权限设置为“已拒绝”,就好像用户收到已拒绝的警报一样 我无法指出这背后的任何理性问题,除了一些过时版本的遗留设置,这些设置在安装新版本时不会被删除。此视图似乎是唯一可能触发这些警报的地方iOS权限警报问题,ios,xcode,permissions,alert,ios-permissions,Ios,Xcode,Permissions,Alert,Ios Permissions,我认为: 使用调用选择器为UIApplicationIDBecMeactiveNotification创建观察者 按顺序向用户请求权限:使用相机、定位和接收推送通知。 该视图有三个UIButton,其状态取决于每个权限状态,如果拒绝任何权限,则这些UIButton会将用户导航到设置 点击表示具有拒绝状态的权限的按钮可将用户导航到设置 一旦使用观察者操作隐藏每个警报,将触发下一个警报,并更新所有按钮状态以反映任何更改 一旦授予了所有权限,它将推送下一个视图以及注册/导入流的其余部分 问题是:在某些
是否有人有类似的问题,可以提出建议?我建议您在要求用户使用定位服务和通知服务之前,尝试检查其状态。因为如果用户要在您请求他许可时禁用这些,他将需要转到设置并在那里启用它。您应该尝试检测用户是否禁用了位置/通知/摄像头 照相机使用:
func accessToCamera(granted: @escaping (() -> Void)) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)
if status == .authorized {
granted()
} else if status == .denied {
self.cameraPermissionAlert()
} else if status == .notDetermined {
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (accessAllowed) in
if accessAllowed {
granted()
} else {
self.cameraPermissionAlert()
}
})
} else if status == .restricted {
self.cameraPermissionAlert()
}
} else {
print("Camera not available on this device")
}
}
func cameraPermissionAlert() {
let alert = UIAlertController(title: "Access to camera not available", message: "Please enable access to camera in order to use this feature", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
if let url = URL(string: UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
if let top = UIApplication.topViewController() { // This is extension to UIApplication that finds top view controller and displays it
top.present(alert, animated: true, completion: nil)
}
}
对于远程通知,您可以使用如下内容:
至于定位服务:
在这两种情况下,您都可以检测用户是否禁用了此功能,并向用户提供具有打开设置功能的警报控制器。我建议您在要求用户使用之前,尝试检查位置服务和通知服务的状态。因为如果用户要在您请求他许可时禁用这些,他将需要转到设置并在那里启用它。您应该尝试检测用户是否禁用了位置/通知/摄像头 照相机使用:
func accessToCamera(granted: @escaping (() -> Void)) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)
if status == .authorized {
granted()
} else if status == .denied {
self.cameraPermissionAlert()
} else if status == .notDetermined {
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (accessAllowed) in
if accessAllowed {
granted()
} else {
self.cameraPermissionAlert()
}
})
} else if status == .restricted {
self.cameraPermissionAlert()
}
} else {
print("Camera not available on this device")
}
}
func cameraPermissionAlert() {
let alert = UIAlertController(title: "Access to camera not available", message: "Please enable access to camera in order to use this feature", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
if let url = URL(string: UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
if let top = UIApplication.topViewController() { // This is extension to UIApplication that finds top view controller and displays it
top.present(alert, animated: true, completion: nil)
}
}
对于远程通知,您可以使用如下内容:
至于定位服务:
在这两种情况下,您都可以检测用户是否禁用此功能,并向用户提供具有“打开设置”功能的警报控制器。无论您是否删除应用程序,部分权限都会存储在iOS中24小时。您可以通过使用不同的捆绑ID启动应用程序,或手动重置iOS设置中的所有权限来强制重新显示。我已尝试删除该应用程序,重置位置和隐私设置,然后重新安装该应用程序。同样的情况有些权限会在iOS中存储24小时,无论您是否删除了应用程序。您可以通过使用不同的捆绑ID启动应用程序,或手动重置iOS设置中的所有权限来强制重新显示。我已尝试删除该应用程序,重置位置和隐私设置,然后重新安装该应用程序。同样的情况