0

PHPicker 适用于大多数视频,但有些视频不返回 typeIdentifier。有谁知道为什么?

这是设置代码

func makeUIViewController(context: Context) -> PHPickerViewController {
    var config = PHPickerConfiguration()
    config.filter = .videos
    config.selectionLimit = 1
    config.preferredAssetRepresentationMode = .current
    
    let controller = PHPickerViewController(configuration: config)
    controller.delegate = context.coordinator
    return controller
}

然后,在 Coordinator:PHPickerViewControllerDelegate 类中......

    func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {

        if !results.isEmpty {
            
            for result in results {
                let itemProvider = result.itemProvider
                
                guard let typeIdentifier = itemProvider.registeredTypeIdentifiers.first,
                      let utType = UTType(typeIdentifier)
                else { continue }
                
                if utType.conforms(to: .image) {
                    self.getPhoto(from: itemProvider, isLivePhoto: false)
                } else if utType.conforms(to: .movie) {
                    self.getVideo(from: itemProvider, typeIdentifier: typeIdentifier)
                } else {
                    self.getPhoto(from: itemProvider, isLivePhoto: true)
                }
            }
            
        } else {
            parent.didFinishPicking(!results.isEmpty)
        }
    }

在这一行:

guard let typeIdentifier = itemProvider.registeredTypeIdentifiers.first,

对于某些视频,它返回正确的视频标识符(例如,com.apple.quicktime-movie),但对于其他视频,例如一小时长的视频,视频标识符为空。

有什么理由吗?视频是本地的,而不是在 iCloud 中。

4

0 回答 0