如何通过iphone中的电子邮件发送.caf文件?

时间:2012-09-06 07:40:27

标签: iphone objective-c mfmailcomposeviewcontroller

我想通过iphone中的电子邮件发送扩展名为.caf的音频文件。任何人都可以帮我这样做吗?我写过mimeType:@"audio/caf",但我认为不支持。请帮我做一个小任务。

1 个答案:

答案 0 :(得分:7)

使用以下代码: -

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:memo.memoUrl];

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filepath];  
NSData *dataToSend = [[NSData alloc] initWithContentsOfURL:fileURL];
[fileURL release];

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Recording"];

// Set up recipients
NSArray *toRecipients = nil;
NSArray *ccRecipients = nil; 
NSArray *bccRecipients = nil;

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

[picker setMessageBody:@"" isHTML:YES];
[picker addAttachmentData:dataToSend mimeType:@"audio/x-caf" fileName:[NSString stringWithFormat:@"voice-memo.caf", memo.memoName]];