在新的 Xcode 12 中,我在权限范围内遇到了一个特殊的错误。 开关必须详尽无遗地添加 .limited 案例。虽然我添加了 .limited case 它仍然显示这个错误。我在使用 switch case 的地方得到了这个。你能为我指出正确的方向吗。我最近将我的项目从 Xcode 11 升级到 Xcode 12,所以在这里有点困惑。
func openPhotoController(item: InfoItem) {
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
DispatchQueue.main.async
{
let photoLib = photoLibViewController()
photoLib.delegate = self
photoLibCropImage = false
photoLib.modalTransitionStyle = .crossDissolve
photoLib.modalPresentationStyle = .fullScreen
photoLib.allowMultipleSelection = false
self.present(photoLib, animated: true, completion: nil)
}
print("authorized")
//handle authorized status
case .denied, .restricted :
print("denied")
AlertManager.showAlertView(title: "Alert?", subtitle: "Please allow access to your photo library to use this functionality", showCancelButton: true, okButtonTitle: "Go to Settings", cancelButtonTitle: "Cancel") {
if let url = URL(string:UIApplication.openSettingsURLString)
{
if UIApplication.shared.canOpenURL(url)
{
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
//handle denied status
case .notDetermined:
// ask for permissions
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
print("authorized")
DispatchQueue.main.async
{
let photoLib = photoLibViewController()
photoLib.delegate = self
photoLibCropImage = false
photoLib.modalTransitionStyle = .crossDissolve
photoLib.modalPresentationStyle = .fullScreen
photoLib.allowMultipleSelection = false
self.present(photoLib, animated: true, completion: nil)
}
// as above
case .denied, .restricted:
print("denied")
// as above
case .notDetermined:
print("notDetermined")
// won't happen but still
case .limited:
print("notDetermined")
default:
print("notDetermined")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在WWDC 2020 中,iOS 14 Apple 引入了一项新功能,该功能将限制对照片库的访问。您缺少.limited外部主开关的外壳。您更新的代码:
switch PHPhotoLibrary.authorizationStatus(for: .readWrite) {
case .notDetermined:
// ask for access
case .restricted, .denied:
// sorry
case .authorized:
// we have full access
// new option:
case .limited:
// we only got access to a part of the library
}
Run Code Online (Sandbox Code Playgroud)
更多,你可以在这里查看
| 归档时间: |
|
| 查看次数: |
3130 次 |
| 最近记录: |