-->

Frequently Camera capture crashing the app without

2019-07-29 11:06发布

问题:

I am using UIIMagePicker Controller for capturing image. The camera capture works fine for first 30 to 40 shots but it will crash the app after around 40 captures. I do not get any memory warning or crash report on xcode.

This issue look like memory leak but i have monitored Instruments and memory use is not going more then 60 MB.

The image pick from gallery do not cause this issue.

Code i am using :-

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

[MBProgressHUD showHUDAddedTo:self.view animated:true];
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"MMM-dd-yyyy";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
timeFormatter.dateFormat = @"HH:mm a";
[timeFormatter setTimeZone:[NSTimeZone systemTimeZone]];   
NSString *strtime=[NSString stringWithFormat:@"%@\n%@ ",[timeFormatter stringFromDate:now],[dateFormatter stringFromDate:now]];
lblTime.numberOfLines =0;
[lblTime setText:strtime];
[lblTime setHidden:YES];
imgTakenPhoto.image = chosenImage;
[btnCrossOnDentView setHidden:YES];
[btnDoneWithDent setHidden:YES];
App_Delegate.isEdited = YES;
[picker dismissViewControllerAnimated:YES completion: ^{

               dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideAllHUDsForView:self.view animated:true];
imagePickerController = nil;
});   }];
}

回答1:

Its an iPhone OS issue. I also submitted a report regarding this issue. Same code will run fine in iPad. Report a bug and submit your project.



回答2:

The best workaround to this is that instead of using UIImagePicker for Camera, use your custom camera view as like WhatsApp, Provide one Capture button onto it to capture as many pics as you want.

Use AVCapture

This will completely remove the burden of opening the Camera Controller.



回答3:

I also faced this problem my current working application. This is because of memory overflow while running your application. I removed unnecessary memory space in application running state. Now my application working fine without any problem.