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

[BugFix - ios] Keep selection order #2099

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ - (NSString *)determineMimeTypeFromImageData:(NSData *)data {
return @"";
}

- (void)qb_imagePickerController:
(QBImagePickerController *)imagePickerController
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController
didFinishPickingAssets:(NSArray *)assets {

PHImageManager *manager = [PHImageManager defaultManager];
Expand All @@ -531,14 +530,19 @@ - (void)qb_imagePickerController:
options.networkAccessAllowed = YES;

if ([[[self options] objectForKey:@"multiple"] boolValue]) {
NSMutableArray *selections = [[NSMutableArray alloc] init];
NSMutableArray *selections = [NSMutableArray arrayWithCapacity:assets.count];

for (int i = 0; i < assets.count; i++) {
[selections addObject:[NSNull null]];
}

[self showActivityIndicator:^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
NSLock *lock = [[NSLock alloc] init];
__block int processed = 0;

for (PHAsset *phAsset in assets) {


for (int index = 0; index < assets.count; index++) {
PHAsset *phAsset = assets[index];

if (phAsset.mediaType == PHAssetMediaTypeVideo) {
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -553,7 +557,7 @@ - (void)qb_imagePickerController:
return;
}

[selections addObject:video];
[selections replaceObjectAtIndex:index withObject:video];
processed++;
[lock unlock];

Expand Down Expand Up @@ -626,22 +630,22 @@ - (void)qb_imagePickerController:
if([[self.options objectForKey:@"includeExif"] boolValue]) {
exif = [[CIImage imageWithData:imageData] properties];
}
[selections addObject:[self createAttachmentResponse:filePath
withExif: exif
withSourceURL:[sourceURL absoluteString]
withLocalIdentifier: phAsset.localIdentifier
withFilename: [phAsset valueForKey:@"filename"]
withWidth:imageResult.width
withHeight:imageResult.height
withMime:imageResult.mime
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
withDuration: nil
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
withRect:CGRectNull
withCreationDate:phAsset.creationDate
withModificationDate:phAsset.modificationDate
]];

[selections replaceObjectAtIndex:index withObject:[self createAttachmentResponse:filePath
withExif: exif
withSourceURL:[sourceURL absoluteString]
withLocalIdentifier: phAsset.localIdentifier
withFilename: [phAsset valueForKey:@"filename"]
withWidth:imageResult.width
withHeight:imageResult.height
withMime:imageResult.mime
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
withDuration: nil
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
withRect:CGRectNull
withCreationDate:phAsset.creationDate
withModificationDate:phAsset.modificationDate
]];
}
processed++;
[lock unlock];
Expand Down