1

当我从相机 ( )Received Memory Warning拍照时,我的应用程序崩溃并显示“ ”。UIImagePickerController

当我遇到崩溃时的场景:如果我的设备上正在运行其他应用程序(2 个或更多),我会遇到崩溃,并且如果在我启动我的应用程序之前只有一个其他应用程序正在运行或没有其他应用程序在运行,那么就没有崩溃了。

仅当我从相机中拍照时才会发生此崩溃,但是当我从照片库中选择图片时根本没有崩溃。

我正在使用 Xcode 4.3.2 并且正在使用 ARC

谁可以帮我这个事?

这是我正在使用的代码

-(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;
}

我的代码有什么问题吗?

4

2 回答 2

0

尝试避免在该方法中分配 UIImagePickerController。而是在 viewDidLoad 中分配它。将这行代码放在 viewDidLoad 中:

 ipc = [[UIImagePickerController alloc] init];

并在 .h 文件中首先声明它。

希望这可以帮助。

于 2013-01-11T07:59:47.273 回答
-2

我终于意识到,通过从项目中删除一些不需要的图像/资源,我能够运行我的应用程序而不会崩溃......!!!感谢所有帮助过我的人!

于 2013-01-17T17:53:49.000 回答