相机捕捉经常在没有任何线索的情况下使应用程序崩溃
Frequently Camera capture crashing the app without any clue
我正在使用 UIIMagePicker 控制器捕获图像。相机捕获在前 30 到 40 张照片中工作正常,但在大约 40 次捕获后它会崩溃应用程序。我在 xcode.
上没有收到任何内存警告或崩溃报告
这个问题看起来像是内存泄漏,但我已经监控了 Instruments 并且内存使用不会超过 60 MB。
从图库中选择的图像不会导致此问题。
我正在使用的代码:-
- (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;
}); }];
}
我目前的工作应用程序也遇到了这个问题。这是因为 运行 您的应用程序内存溢出。我删除了应用程序 运行 状态下不必要的内存 space。现在我的应用程序工作正常,没有任何问题。
这是一个 iPhone OS 问题。我也提交了一份关于这个问题的报告。相同的代码 运行 可以在 iPad 中使用。报告错误并提交您的项目。
最好的解决方法是不要使用 UIImagePicker for Camera,而是像 WhatsApp 一样使用您的自定义相机视图,在其上提供一个拍摄按钮以拍摄任意数量的照片。
这将彻底消除打开相机控制器的负担。
我正在使用 UIIMagePicker 控制器捕获图像。相机捕获在前 30 到 40 张照片中工作正常,但在大约 40 次捕获后它会崩溃应用程序。我在 xcode.
上没有收到任何内存警告或崩溃报告这个问题看起来像是内存泄漏,但我已经监控了 Instruments 并且内存使用不会超过 60 MB。
从图库中选择的图像不会导致此问题。
我正在使用的代码:-
- (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;
}); }];
}
我目前的工作应用程序也遇到了这个问题。这是因为 运行 您的应用程序内存溢出。我删除了应用程序 运行 状态下不必要的内存 space。现在我的应用程序工作正常,没有任何问题。
这是一个 iPhone OS 问题。我也提交了一份关于这个问题的报告。相同的代码 运行 可以在 iPad 中使用。报告错误并提交您的项目。
最好的解决方法是不要使用 UIImagePicker for Camera,而是像 WhatsApp 一样使用您的自定义相机视图,在其上提供一个拍摄按钮以拍摄任意数量的照片。
这将彻底消除打开相机控制器的负担。