Post

Replies

Boosts

Views

Activity

PHPickerViewController - can I use loadInPlaceFileRepresentation instead of loadFileRepresentation?
Hi there, Hi Apple team, I am trying to use PHPickerViewController to load photos and videos, but I got a problem: Option 1. loadFileRepresentation works but I have to copy each time, with video file 1h & 4k it can take too long to wait and consume memory. Option 2. loadInPlaceFileRepresentation fails in the case of files located in the iCloud. with error : [default] [ERROR] Could not create a bookmark: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it." Option 3. Use Photos Framework(with PHAssets) requires access to Photos. Queustion is loadInPlaceFileRepresentation intended to use in this case? test code: static func loadVideoURL(for source: PHPickerResult, completion: @escaping (URL?) - Void) - Progress? {     let itemProvider = source.itemProvider     guard let typeIdentifier = itemProvider.registeredTypeIdentifiers.first, let utType = UTType(typeIdentifier), utType.conforms(to: .movie) else {       fatalError()     }           /*     //     itemProvider.loadFileRepresentation(forTypeIdentifier: typeIdentifier) { url, error in       if let error = error {         print(error.localizedDescription)         fatalError()       }           guard let url = url else { return }           let documentsDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first       guard let targetURL = documentsDirectory?.appendingPathComponent(url.lastPathComponent) else { return }           do {         if FileManager.default.fileExists(atPath: targetURL.path) {           try FileManager.default.removeItem(at: targetURL)         }             try FileManager.default.copyItem(at: url, to: targetURL)             DispatchQueue.main.async {           completion(targetURL)         }       } catch {         print(error.localizedDescription)         fatalError()       }     }     */           ///*     //     let progress = itemProvider.loadInPlaceFileRepresentation(forTypeIdentifier: typeIdentifier, completionHandler: { url, inPlace, error in       guard let url = url else { return }               if inPlace {         DispatchQueue.main.async {           _ = url.startAccessingSecurityScopedResource()           completion(url)           url.stopAccessingSecurityScopedResource()         }       } else {         print("Not InPlace")       }     })           return progress }
1
0
1.5k
Apr ’21