如何在iphone中使用MFMailcomposer在电子邮件中附加m4v视频

时间:2012-08-24 07:43:46

标签: iphone

我正在使用此代码,但它不会发送包含视频的邮件 这是我的代码:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];  
        controller.mailComposeDelegate = self;  
        [controller setSubject:@"My Subject"];  
        [controller setMessageBody:@"" isHTML:NO]; if (controller) [self presentModalViewController:controller animated:YES];  
        [controller release];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:titleString];

        NSLog(@"datapath=%@",dataPath);

        NSURL *url=[[NSURL alloc] initFileURLWithPath:dataPath];

        NSLog(@"url..%@",url);

        NSData *data=[[NSData alloc]initWithContentsOfURL:url ];

  [controller addAttachmentData:data mimeType:@"video/quicktime" fileName:titleString];

plzz帮帮我

1 个答案:

答案 0 :(得分:1)

这是代码

-(void)displayComposerSheet 
{
  MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
  picker.mailComposeDelegate = self;

 [picker setSubject:@"Subject Name"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:emailsenderaddress]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"", @"", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@""]; 

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];  
[picker setBccRecipients:bccRecipients];

// Attach an file to the email


// Fill out the email body text
NSString *emailBody = [NSString stringWithFormat:@""];
[picker setMessageBody:emailBody isHTML:NO];

NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *saveDirectory = [documentPath objectAtIndex:0];

NSString *saveFileName = [NSString stringWithFormat:@"fileNmae%@.m4v",[invoiceidarray objectAtIndex:OptionView.tag]];

NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];

NSData *pdfData = [NSData dataWithContentsOfFile:finalPath];
[picker addAttachmentData:pdfData mimeType:@"application/m4v" fileName:saveFileName];
[self presentModalViewController:picker animated:YES];
[picker release];

}