Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): 🐛 Image Picker to Handle Partial Failures Gracefully #1639

Merged

Conversation

bahadurh
Copy link
Contributor

@bahadurh bahadurh commented Nov 29, 2024

Problem

Currently, the iOS image picker fails entirely if any single image fails to process, causing a poor user experience.

Error:
PlatformException(file_picker_error, Temporary file could not be created, Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.item" UserInfo={NSLocalizedDescription=Cannot load representation of type public.item, NSUnderlyingError=0x303587d50 {Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x303572be0 {Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 18859 named (null) was invalidated." UserInfo={NSDebugDescription=The connection to service with pid 18859 named (null) was invalidated.}}}}}, null)

Solution

Updated the PHPicker implementation to:

  • Handle each image independently, allowing partial successes
  • Prevent crashes by implementing proper type checking and error handling
  • Improve temporary file management
  • Add detailed error logging for debugging

Key changes:

  1. Removed all-or-nothing approach for multiple image selection
  2. Added proper error collection without failing the entire operation
  3. Implemented better memory management with autoreleasepool
  4. Added unique filename generation to prevent conflicts
  5. Improved error messages for debugging
  6. Added proper null/type checking for URL handling

Testing

Tested scenarios:

  • Selecting multiple images (mix of local and iCloud images)
  • Selecting single image
  • Canceling selection
  • Handling invalid file types
  • Memory usage with large selections
  • iCloud asset download failures

Impact

Users can now select multiple images and get results even if some images fail to process, rather than losing all selected images due to a single failure.

## Problem
Currently, the iOS image picker fails entirely if any single image fails to process, causing a poor user experience. Additionally, there's a crash when attempting to access the path property of an NSDictionary, resulting in app termination.

## Solution
Updated the PHPicker implementation to:
- Handle each image independently, allowing partial successes
- Prevent crashes by implementing proper type checking and error handling
- Improve temporary file management
- Add detailed error logging for debugging

Key changes:
1. Removed all-or-nothing approach for multiple image selection
2. Added proper error collection without failing the entire operation
3. Implemented better memory management with @autoreleasepool
4. Added unique filename generation to prevent conflicts
5. Improved error messages for debugging
6. Added proper null/type checking for URL handling

## Testing
Tested scenarios:
- Selecting multiple images (mix of local and iCloud images)
- Selecting single image
- Canceling selection
- Handling invalid file types
- Memory usage with large selections
- iCloud asset download failures

## Impact
Users can now select multiple images and get results even if some images fail to process, rather than losing all selected images due to a single failure.
@bahadurh
Copy link
Contributor Author

bahadurh commented Dec 4, 2024

fixed #1554, #951

@miguelpruivo
Copy link
Owner

Hi! Looks great, thank you!

Can you please bump the patch version and also update the changelog accordingly? Thanks.

@miguelpruivo miguelpruivo self-assigned this Dec 11, 2024
@bahadurh
Copy link
Contributor Author

Hi! Looks great, thank you!

Can you please bump the patch version and also update the changelog accordingly? Thanks.

DONE 🔥

@miguelpruivo miguelpruivo merged commit 9b17617 into miguelpruivo:master Dec 26, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants