0

カメラや写真ライブラリから撮った写真でメールを作成したい。しかし、メール コンポーザー ピッカーを開くことができません。

これが私のコードです:

-(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!

どうすればこれを処理できますか。

4

1 に答える 1

2

問題は、最初に 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];
                                 }
                             }];
}

それが役に立てば幸い!

于 2013-06-05T09:08:28.590 に答える