Swift 在Xcode 12中,开关必须是穷举的

Swift 在Xcode 12中,开关必须是穷举的,swift,xcode12,Swift,Xcode12,在新的Xcode 12中,我在权限范围中遇到了一个特殊的错误。 开关必须是穷举添加。有限大小写。虽然我添加了。有限大小写它仍然显示此错误。我在使用开关箱的地方得到这个。你能给我指一下正确的方向吗。我最近将我的项目从Xcode 11升级到了Xcode 12,所以我在这里有点困惑 func openPhotoController(item: InfoItem) { let status = PHPhotoLibrary.authorizationStatus()

在新的Xcode 12中,我在权限范围中遇到了一个特殊的错误。 开关必须是穷举添加。有限大小写。虽然我添加了。有限大小写它仍然显示此错误。我在使用开关箱的地方得到这个。你能给我指一下正确的方向吗。我最近将我的项目从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")
            }  
        }
    }
}

为外部开关添加
.limited
外壳

如果您不想处理它,您可以始终插入一个默认情况(您的内部开关有此情况,但外部开关没有此情况):

。。。
违约:
//否则,做点别的

Swift开关上的文件:.

为外部开关添加
.limited
外壳

如果您不想处理它,您可以始终插入一个默认情况(您的内部开关有此情况,但外部开关没有此情况):

。。。
违约:
//否则,做点别的

Swift switch上的文档:.

在WWDC 2020中,iOS 14苹果推出了一项新功能,该功能将限制对照片库的访问。您缺少外部主开关的
.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
}

如需了解更多信息,请查看《WWDC 2020》中的

iOS 14苹果推出了一项新功能,该功能将限制对照片库的访问。您缺少外部主开关的
.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
}

有关更多信息,您可以检查有两个开关。外部开关(父开关)没有“case.limited”。谢谢,我有点惊慌失措,忘记了基本设置。这里有2个开关。外部开关(父开关)没有“case.limited”。Thank有点惊慌失措,忘记了基本的设置