@@ -521,8 +521,7 @@ - (NSString *)determineMimeTypeFromImageData:(NSData *)data {
521521 return @" " ;
522522}
523523
524- - (void )qb_imagePickerController :
525- (QBImagePickerController *)imagePickerController
524+ - (void )qb_imagePickerController : (QBImagePickerController *)imagePickerController
526525 didFinishPickingAssets : (NSArray *)assets {
527526
528527 PHImageManager *manager = [PHImageManager defaultManager ];
@@ -531,14 +530,19 @@ - (void)qb_imagePickerController:
531530 options.networkAccessAllowed = YES ;
532531
533532 if ([[[self options ] objectForKey: @" multiple" ] boolValue ]) {
534- NSMutableArray *selections = [[ NSMutableArray alloc ] init ];
533+ NSMutableArray *selections = [NSMutableArray arrayWithCapacity: assets.count ];
535534
535+ for (int i = 0 ; i < assets.count ; i++) {
536+ [selections addObject: [NSNull null ]];
537+ }
538+
536539 [self showActivityIndicator: ^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
537540 NSLock *lock = [[NSLock alloc ] init ];
538541 __block int processed = 0 ;
539-
540- for (PHAsset *phAsset in assets) {
541-
542+
543+ for (int index = 0 ; index < assets.count ; index++) {
544+ PHAsset *phAsset = assets[index];
545+
542546 if (phAsset.mediaType == PHAssetMediaTypeVideo) {
543547 [self getVideoAsset: phAsset completion: ^(NSDictionary * video) {
544548 dispatch_async (dispatch_get_main_queue (), ^{
@@ -553,7 +557,7 @@ - (void)qb_imagePickerController:
553557 return ;
554558 }
555559
556- [selections addObject : video];
560+ [selections replaceObjectAtIndex: index withObject : video];
557561 processed++;
558562 [lock unlock ];
559563
@@ -626,22 +630,22 @@ - (void)qb_imagePickerController:
626630 if ([[self .options objectForKey: @" includeExif" ] boolValue ]) {
627631 exif = [[CIImage imageWithData: imageData] properties ];
628632 }
629-
630- [selections addObject : [self createAttachmentResponse: filePath
631- withExif: exif
632- withSourceURL: [sourceURL absoluteString ]
633- withLocalIdentifier: phAsset.localIdentifier
634- withFilename: [phAsset valueForKey: @" filename" ]
635- withWidth: imageResult.width
636- withHeight: imageResult.height
637- withMime: imageResult.mime
638- withSize: [NSNumber numberWithUnsignedInteger: imageResult.data.length]
639- withDuration: nil
640- withData: [[self .options objectForKey: @" includeBase64" ] boolValue ] ? [imageResult.data base64EncodedStringWithOptions: 0 ]: nil
641- withRect: CGRectNull
642- withCreationDate: phAsset.creationDate
643- withModificationDate: phAsset.modificationDate
644- ]];
633+
634+ [selections replaceObjectAtIndex: index withObject : [self createAttachmentResponse: filePath
635+ withExif: exif
636+ withSourceURL: [sourceURL absoluteString ]
637+ withLocalIdentifier: phAsset.localIdentifier
638+ withFilename: [phAsset valueForKey: @" filename" ]
639+ withWidth: imageResult.width
640+ withHeight: imageResult.height
641+ withMime: imageResult.mime
642+ withSize: [NSNumber numberWithUnsignedInteger: imageResult.data.length]
643+ withDuration: nil
644+ withData: [[self .options objectForKey: @" includeBase64" ] boolValue ] ? [imageResult.data base64EncodedStringWithOptions: 0 ]: nil
645+ withRect: CGRectNull
646+ withCreationDate: phAsset.creationDate
647+ withModificationDate: phAsset.modificationDate
648+ ]];
645649 }
646650 processed++;
647651 [lock unlock ];
0 commit comments