【问题标题】:In iPhone 3.0, Application crashes when trying to send an image from the camera using MessageUI在 iPhone 3.0 中,应用程序在尝试使用 MessageUI 从相机发送图像时崩溃
【发布时间】:2009-09-08 07:58:34
【问题描述】:

我正在开发 iPhone 应用程序的一部分,您可以在其中使用 iPhone 3.0 中的应用程序内邮件发送图像。从相机胶卷中选择图像效果很好,但是当我尝试从相机转到电子邮件时(即 - 从 UIImagePickerController 到 MFMailComposeViewController),应用程序崩溃了。

这是运行相机的代码:

- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegateObject 
{
    if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil)) 
        return NO;
    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = delegateObject;
    picker.allowsImageEditing = NO;
    [controller presentModalViewController:picker animated:YES];
    return YES;
}

这是完成相机的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    NSLog(@"Called finish picking");
    self.imageForSending = theImage;

    //   NSData *imageData = UIImageJPEGRepresentation(image, 1);

    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    [(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] recoverNavigationBar];

    [self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45];
    [picker release];
}

这是发送邮件的代码:

- (void) sendEmail {

    [(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] hideNavigationBar];
    if (![MFMailComposeViewController canSendMail])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"שגיאה", @"") message:NSLocalizedString(@"לא ניתן לשלוח מייל ממכשיר זה", @"")
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];   
        [alert release];
    }
    else
    {
        MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
        controller.mailComposeDelegate = self;
        [[controller navigationBar] setTintColor:[UIColor colorWithRed:120.0/255.0 green:0 blue:0 alpha:1.0]];
        NSData *imageData = UIImageJPEGRepresentation(imageForSending, 1);
        [controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"storyImage.jpg"];
        [controller setSubject:@""];
        [controller setToRecipients:[NSArray arrayWithObject:@""]];
        [self presentModalViewController:controller animated:YES];
        [controller release];
    }

}

我删除了电子邮件地址和主题,因为它不太相关。

崩溃发生在邮件的presentModalViewController。再次 - 当从相机胶卷中选择图像时,这个确切的代码可以完美地工作......

帮助? 我已经和这个打了一段时间,真的可以使用一些新的输入。 谢谢!

【问题讨论】:

    标签: iphone-sdk-3.0 crash camera uiimagepickercontroller mfmailcomposeviewcontroller


    【解决方案1】:

    大家好,我找到了自己问题的答案。 这是两个模态视图控制器呈现之间的时间问题

    基本上,我已经知道这是一个问题,但是,我没有等待足够长的时间。 等待足以从相机胶卷中选择图像,但不足以从相机中返回。

    [self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45];

    改为:

    [self performSelector:@selector(sendEmail) withObject:nil afterDelay:1.0];

    我还添加了一个 UIActivityIndi​​cator 来指示用户正在发生的事情。

    编码愉快!

    【讨论】:

      猜你喜欢
      • 2018-01-14
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多