@@ -565,7 +565,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
565565 [result.itemProvider loadFileRepresentationForTypeIdentifier: typeIdentifier completionHandler: ^(NSURL * _Nullable url, NSError * _Nullable error) {
566566 @autoreleasepool {
567567 if (error != nil || url == nil ) {
568- [errors addObject: [NSString stringWithFormat: @" Failed to load image at index %ld : %@ " ,
568+ [errors addObject: [NSString stringWithFormat: @" Failed to load image/video at index %ld : %@ " ,
569569 (long )index, error ? error.localizedDescription : @" Unknown error" ]];
570570 dispatch_group_leave (self->_group );
571571 return ;
@@ -583,26 +583,17 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
583583
584584 // Load image data with options to reduce memory usage
585585 NSError *loadError = nil ;
586- NSData *imageData = [NSData dataWithContentsOfURL: url options: NSDataReadingMappedIfSafe error: &loadError];
587586
588- if (loadError || !imageData) {
589- [errors addObject: [ NSString stringWithFormat: @" Failed to load image data at index %ld : %@ " ,
590- ( long )index, loadError.localizedDescription ?: @" Unknown error " ] ];
587+ // Write to destination
588+ if ([[ NSFileManager defaultManager ] copyItemAtURL: url toURL: destinationUrl error: &loadError]) {
589+ [urls addObject: destinationUrl ];
591590 } else {
592- // Write to destination
593- if ([imageData writeToURL: destinationUrl options: NSDataWritingAtomic error: &loadError]) {
594- [urls addObject: destinationUrl];
595- } else {
596- [errors addObject: [NSString stringWithFormat: @" Failed to save image at index %ld : %@ " ,
597- (long )index, loadError.localizedDescription]];
598- }
591+ [errors addObject: [NSString stringWithFormat: @" Failed to save image/video at index %ld : %@ " ,
592+ (long )index, loadError.localizedDescription]];
599593 }
600594
601- // Clean up
602- imageData = nil ;
603-
604595 } @catch (NSException *exception) {
605- [errors addObject: [NSString stringWithFormat: @" Exception processing image at index %ld : %@ " ,
596+ [errors addObject: [NSString stringWithFormat: @" Exception processing image/video at index %ld : %@ " ,
606597 (long )index, exception.description]];
607598 }
608599
@@ -642,7 +633,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
642633 } else {
643634 // Only if all images failed, return an error
644635 self->_result ([FlutterError errorWithCode: @" file_picker_error"
645- message: @" Failed to process any images"
636+ message: @" Failed to process any images/video "
646637 details: [errors componentsJoinedByString: @" \n " ]]);
647638 }
648639 self->_result = nil ;
0 commit comments