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

[Bug report][ios] Getting low quality image when requesting for iCloud origin file #1118

Open
ua741 opened this issue Apr 18, 2024 · 3 comments

Comments

@ua741
Copy link
Contributor

ua741 commented Apr 18, 2024

Version

3.0.0

Platforms

iOS

Device Model

All iPhone Devices

flutter info

flutter 3.19.5

How to reproduce?

Unfortunately, we don't have any reliable way to reproduce this particular issue.
On iOS, multiple customers have reported that the app is showing lowered quality photo.

  • All affected customers have iCloud backup enabled.
  • It only happens with few photos, not all.
  • From what we know, all these users have enabled Optimize (device) Storage option. When enabled, iOS stores a low quality version of the original file to save space.

Potential Root Cause

After a quick search on SO, I found following posts that are sort of related to this potential issue.
https://stackoverflow.com/a/31784955

 PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
 options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; //I only want the highest possible quality
 options.synchronous = NO;
 options.networkAccessAllowed = YES;
 options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
        NSLog(@"%f", progress); //follow progress + update progress bar
    };

  [[PHImageManager defaultManager] requestImageForAsset:myPhAsset targetSize:self.view.frame.size contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
        NSLog(@"reponse %@", info);
        NSLog(@"got image %f %f", image.size.width, image.size.height);
    }];

https://stackoverflow.com/a/27700985

If -[PHImageRequestOptions isSynchronous] returns NO (or options is nil), resultHandler may be called 1 or more times.
Typically in this case, resultHandler will be called asynchronously on the main thread with the requested results. However, if deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic, resultHandler may be called synchronously on the calling thread if any image data is immediately available. If the image data returned in this first pass is of insufficient quality, resultHandler will be called again, asychronously on the main thread at a later time with the "correct" results. If the request is cancelled, resultHandler may not be called at all. If -[PHImageRequestOptions isSynchronous] returns YES, resultHandler will be called exactly once, synchronously and on the calling thread. Synchronous requests cannot be cancelled. resultHandler for asynchronous requests, always called on main thread


Current Photo Manager Implementation

Link

....
    PHAssetResourceRequestOptions *options = [PHAssetResourceRequestOptions new];
    [options setNetworkAccessAllowed:YES];
    [self notifyProgress:progressHandler progress:0 state:PMProgressStatePrepare];
    [options setProgressHandler:^(double progress) {
        if (progress != 1) {
            [self notifyProgress:progressHandler progress:progress state:PMProgressStateLoading];
        }
    }];

    PHAssetResourceManager *resourceManager = PHAssetResourceManager.defaultManager;
    NSURL *fileUrl = [NSURL fileURLWithPath:path];
    [resourceManager writeDataForAssetResource:imageResource
                                        toFile:fileUrl
                                       options:options
                             completionHandler:^(NSError *_Nullable error) {
        if (error) {
            NSLog(@"error = %@", error);
            [self notifyProgress:progressHandler progress:0 state:PMProgressStateFailed];
            [handler replyError:[NSString stringWithFormat:@"%@", error]];
        } else {
            [handler reply:path];
            [self notifySuccess:progressHandler];
        }
    }];

In PHAssetResourceRequestOptions (used by flutter_photo_manager), unlike PHImageRequestOptions, there's no way to specify deliveryMode of the image, that can impact the quality of the file.

Logs

NA

Example code (optional)

No response

Contact

No response

@AlexV525
Copy link
Member

How about videos?

@ua741
Copy link
Contributor Author

ua741 commented Jul 30, 2024

How about videos?

Our customers have reported this issue for images only. No one has (yet) said the same about video.

@AlexV525
Copy link
Member

One thing I cannot understand is we fetch the origin resource instead of choosing any delivery mode, which should not have quality issues in common sense? Choosing a delivery mode should result in non-original resource eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants