简体   繁体   中英

How can I send .mov recorder file from iOS app through mail as attachments

I am recording an audio and saving it in my device ,and I want to send that recorded audio as a mail attachment.Currently I am able to send this as mail but the problem is when I download the attachment its actually a "data" type file instead of ".mov" file. So I am not able to play that downloaded file..

Here is the code used to send as mail.

- (IBAction)submit:(id)sender {

    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;

        [mailer setSubject:@"eGift"];

        NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
        [mailer setToRecipients:toRecipients];

//        UIImage *myImage = galleryimage.image;
        NSData *imageData = [NSData dataWithContentsOfFile:recordFile];
     //   NSLog(@"%@",imageData);
        [mailer addAttachmentData:imageData mimeType:@"audio/mov" fileName:@"naveen"];


        NSString *emailBody = _smsText.text;
        [mailer setMessageBody:emailBody isHTML:NO];

        // only for iPad
        // mailer.modalPresentationStyle = UIModalPresentationPageSheet;

        [self presentModalViewController:mailer animated:YES];

        //            } else {
        //                NSLog(@"Error in resultblock in PhotoAlbumViewController!");
        //            }
        //        };



        //[mailer release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        // [alert release];
    }

}



#pragma mark - MFMailComposeController delegate


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the Drafts folder");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
            break;
        default:
            NSLog(@"Mail not sent");
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

You're just missing the suffix to the file type... (ie. the .mov in your filename: below).

did a quick update to your code

[mailer addAttachmentData:imageData mimeType:@"audio/mov" fileName:[recordFile lastPathComponent]];

Works for me now and opens w/ quicktime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM