iOS相机内存警告的解决办法

1.先释放。

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

方法里面首先调用

[picker dismissViewControllerAnimated:YES completion:nil];

2.相机调成低画质。

picker.videoQuality = UIImagePickerControllerQualityTypeLow;

3.裁剪图片

[NSThread detachNewThreadSelector:@selector(useImage:) toTarget:self withObject:image];

- (void)useImage:(UIImage *)image
{
    CGSize size = CGSizeMake(106, 106);
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [imageView setImage:newImage forState:UIControlStateNormal];
}

这么一来,虽然还会受到内存警告,但是闪退的问题大大的减轻了。

你可能感兴趣的:(iOS知识点,错误整理)