My App crashes saying "Received Memory Warning
" when i take a picture from camera (UIImagePickerController
).
Scenario when i get the crash: If I have other apps running on my device(2 or more), I am getting the crash and if there is only one other app running or no other apps running before I launch my app then there are no crashes at all.
This crash happens only when i take the picture from my camera but when i choose the picture from photo library there is no crash at all.
I am using Xcode 4.3.2 and I am using ARC.
Can any one help me on this?
This is the code i am using
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex: (NSInteger)buttonIndex
{
if (buttonIndex < 2)
{
if([UIImagePickerController isSourceTypeAvailable:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
[ipc setDelegate:(id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>) self];
[ipc setSourceType:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary];
if (buttonIndex == 0)
{
[ipc setAllowsEditing:NO];
}
[ipc setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]];
[self presentModalViewController:ipc animated:YES];
}
else
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Action Alert" message:@"Camera is not available in this device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];
[NSThread detachNewThreadSelector:@selector(scallImage:) toTarget:self withObject:image];
}
-(void) scallImage:(UIImage *) image
{
CGSize newSize = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
image=nil;
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *cImage = [UIImageJPEGRepresentation(newImage, 0.5) base64EncodedString];
[ImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
[ImageButton setHidden:NO];
//[profileImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
newImage=nil;
}
Is there any thing wrong in my code?
I finally realized that by removing some of the unwanted images/resources from the project I am able to run my app without crashes ...!!! Thanks everyone who helped me !