@@ -521,8 +521,7 @@ - (NSString *)determineMimeTypeFromImageData:(NSData *)data {
521
521
return @" " ;
522
522
}
523
523
524
- - (void )qb_imagePickerController :
525
- (QBImagePickerController *)imagePickerController
524
+ - (void )qb_imagePickerController : (QBImagePickerController *)imagePickerController
526
525
didFinishPickingAssets : (NSArray *)assets {
527
526
528
527
PHImageManager *manager = [PHImageManager defaultManager ];
@@ -531,14 +530,19 @@ - (void)qb_imagePickerController:
531
530
options.networkAccessAllowed = YES ;
532
531
533
532
if ([[[self options ] objectForKey: @" multiple" ] boolValue ]) {
534
- NSMutableArray *selections = [[ NSMutableArray alloc ] init ];
533
+ NSMutableArray *selections = [NSMutableArray arrayWithCapacity: assets.count ];
535
534
535
+ for (int i = 0 ; i < assets.count ; i++) {
536
+ [selections addObject: [NSNull null ]];
537
+ }
538
+
536
539
[self showActivityIndicator: ^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
537
540
NSLock *lock = [[NSLock alloc ] init ];
538
541
__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
+
542
546
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
543
547
[self getVideoAsset: phAsset completion: ^(NSDictionary * video) {
544
548
dispatch_async (dispatch_get_main_queue (), ^{
@@ -553,7 +557,7 @@ - (void)qb_imagePickerController:
553
557
return ;
554
558
}
555
559
556
- [selections addObject : video];
560
+ [selections replaceObjectAtIndex: index withObject : video];
557
561
processed++;
558
562
[lock unlock ];
559
563
@@ -626,22 +630,22 @@ - (void)qb_imagePickerController:
626
630
if ([[self .options objectForKey: @" includeExif" ] boolValue ]) {
627
631
exif = [[CIImage imageWithData: imageData] properties ];
628
632
}
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
+ ]];
645
649
}
646
650
processed++;
647
651
[lock unlock ];
0 commit comments