Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过电子邮件从照片库发送图片_Ios_Objective C_Uiimagepickercontroller_Mfmailcomposeviewcontroller - Fatal编程技术网

Ios 通过电子邮件从照片库发送图片

Ios 通过电子邮件从照片库发送图片,ios,objective-c,uiimagepickercontroller,mfmailcomposeviewcontroller,Ios,Objective C,Uiimagepickercontroller,Mfmailcomposeviewcontroller,我想用相机或照片库拍摄的照片撰写一封电子邮件。但我无法打开Mail composer picker 这是我的密码: -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { [self dismissModalViewControllerAnimated:YES]; UIImage* image_type=[in

我想用相机或照片库拍摄的照片撰写一封电子邮件。但我无法打开Mail composer picker

这是我的密码:

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    [self dismissModalViewControllerAnimated:YES];
    UIImage* image_type=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
    dataImage = UIImagePNGRepresentation(image_type);

    if([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
        mailCont.delegate=self;
        mailCont.mailComposeDelegate = self;        // Required to invoke mailComposeController when send
        [mailCont setSubject:@""];
        [mailCont setToRecipients:[NSArray arrayWithObject:@""]];
        [mailCont addAttachmentData:dataImage mimeType:@"image/png" fileName:@"sender_image.png"];
        [mailCont setMessageBody:@"" isHTML:NO];

        [self presentModalViewController:mailCont animated:YES];
    }
}
现在邮件选择器没有打开。警告是:

Warning: Attempt to present <MFMailComposeViewController: 0xa26b070> on <UINavigationController: 0xa22e6d0> while a presentation is in progress!
警告:在演示过程中尝试在上演示!

如何处理此问题。

您的问题是,首先要关闭UIImagePicker,然后立即尝试将另一个视图显示为模式视图。这必须在解雇结束后进行。请尝试以下方法:

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 UIImage* image_type=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
                                 dataImage = UIImagePNGRepresentation(image_type);

                                 if([MFMailComposeViewController canSendMail])
                                 {
                                     MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
                                     mailCont.delegate=self;
                                     mailCont.mailComposeDelegate = self;        // Required to invoke mailComposeController when send
                                     [mailCont setSubject:@""];
                                     [mailCont setToRecipients:[NSArray arrayWithObject:@""]];
                                     [mailCont addAttachmentData:dataImage mimeType:@"image/png" fileName:@"sender_image.png"];
                                     [mailCont setMessageBody:@"" isHTML:NO];

                                     [self presentModalViewController:mailCont animated:YES];
                                 }
                             }];
}

希望有帮助

您可以将邮件编写代码转移到一个单独的函数,并使用performSelector:withObject:afterDelay:@Adi延迟调用该函数。这不是一个最佳解决方案,因为在任意时间ε后,没有任何一个garantie会被解雇。应该在视图结束后完成。谢谢@PraveenS告诉我新的内容。。它很好用…@Filip当然。。同意。谢谢@filip。。它的效果很好。。快乐编码…)@希瓦姆甜!也许+1和公认的答案是合适的!;)