在 iPhone 3.0 中,尝试使用 MessageUI 从相机发送图像时应用程序崩溃

发布于 2024-08-03 23:01:29 字数 2839 浏览 2 评论 0原文

我正在开发 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];
    }

}

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

崩溃发生在当前电子邮件的ModalViewController 上。再说一遍 - 当从相机胶卷中选择图像时,这个确切的代码可以完美地工作......

帮助? 我已经和这个问题斗争了一段时间了,确实需要一些新的输入。 谢谢!

There is a part of the iPhone app that I'm developing where you can send images using the in app mail in iPhone 3.0. Selecting an image from the camera roll works perfectly, but when I try to go from the camera to the email (ie - from the UIImagePickerController to the MFMailComposeViewController), the application crashes.

This is the code for running the camera :

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

And this is the code for finishing with the camera :

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

And this is the code for sending the mail :

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

}

I erased the email address and the subject since it is less relevant.

The crash happens at presentModalViewController of the email. Again - this exact code work perfectly when selecting an image from the camera roll...

Help ?
I've been fighting with this one for a while and could really use some new input.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最好是你 2024-08-10 23:01:29

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

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

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

更改为:

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

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

编码愉快!

Hi to anyone watching, I found the answer to my own question.
Its a timing issue between the presentation of two modal view controllers

Basically, I already knew that this was an issue, but, I hadn't put in a long enough wait.
The wait was enough for selecting an image from the camera roll but not long enough for coming back from the camera.

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

changed to :

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

I also added an UIActivityIndicator to indicate that something is happening for the user.

Happy coding !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文