Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Gallery picker : NSArrayM-insertObjectatIndex-object-cannot-be-nil #207

Open
maxz044679 opened this issue Jan 3, 2018 · 2 comments
Open

Comments

@maxz044679
Copy link

  • (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray )assets{
    @Try{
    PHImageRequestOptions
    requestOptions = [[PHImageRequestOptions alloc] init];
    requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
    requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    requestOptions.synchronous = true;

      PHImageManager *manager = [PHImageManager defaultManager];
      for (PHAsset *asset in assets) {
          
          [manager requestImageForAsset:asset
                             targetSize:PHImageManagerMaximumSize
                            contentMode:PHImageContentModeDefault
                                options:requestOptions
                          resultHandler:^void(UIImage *image, NSDictionary *info) {
                              NSMutableArray* inner = [[NSMutableArray alloc]init];
                              
                              NSDate *now = [NSDate date];
                              NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
                              NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                              [formatter setCalendar:gregorianCalendar];
                              [formatter setDateFormat:@"yyyy-MM-dd-HHmmssSSS"];
                              NSString *filename;
                              if([_page integerValue] == 0){
                                  filename = [NSString stringWithFormat:@"%@_%@_0_%@"
                                              ,dataController.getEvaluationID
                                              ,dataController.getHoleID
                                              ,[formatter stringFromDate:now]];
                              } else {
                                  filename = [NSString stringWithFormat:@"%@_%@_%@_%@"
                                              ,dataController.getEvaluationID
                                              ,dataController.getHoleID
                                              ,dataController.getCategoryID
                                              ,[formatter stringFromDate:now]];
                              }
                              
                              NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                              NSString *documentsDirectory = [paths objectAtIndex:0];
                              NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg" , filename]];
                              
                              [inner addObject:filename];
                              [inner addObject:localFilePath];
                              [inner addObject:image];
                              [photo addObject:inner];
                          }];
      }
      [self insertImageToScrollView];
      [self dismissViewControllerAnimated:YES completion:NULL];
    

    } @catch (NSException* exception){
    NSString* str = [NSString stringWithFormat:@"CommentView qb_imagePickerController %@" , [exception reason]];
    [self setErrorReason:str];
    }
    }

[exception reason] show messege
---NSArrayM-insertObjectatIndex-object-cannot-be-nil

some device crash but some are not crash...
what is the possible problem...please help...

thank you.

@nuwanga88
Copy link

Hello,
Did you find the solution?
In my case Image is getting nil and when I try to add into the array its getting crashed.

I want to know why delegate method Image object is getting nil.

Thanks.

@maxz044679
Copy link
Author

No, did not
I use OpalImagePicker instead, compatible with both Swift and Objective-C.(https://github.com/opalorange/OpalImagePicker)

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

No branches or pull requests

2 participants