ios,将音频文件aac格式附加到电子邮件

时间:2013-02-05 15:53:36

标签: ios email avaudioplayer email-attachments mfmailcomposeviewcontroller

我尝试按文件aac(kAudioFormatMPEG4AAC)格式发送音频记录,但附加的文件不发送

* myString = file:// localhost / private / var / mobile .......

这是我的代码

MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"My Audio File"];  
NSString *fileName = @"Rec.aac";  

NSString *documentsDirectory = myString ;

NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
NSData   *data = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:data mimeType:@"audio/aac"
                 fileName:fileName];
NSString *emailBody = @"AAC format sound file attached.";  
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];

1 个答案:

答案 0 :(得分:1)

NSData   *data = [NSData dataWithContentsOfFile:path];

您传入了file://网址,该方法无法理解该网址。该方法只需要一个标准文件路径,即/private/var/mobile/

您可以简单地使用文件路径,但如果您只提供了URL表单字符串,则可以创建一个URL对象并将其与NSData一起使用。

NSURL* fileURL = [NSURL URLwithString:myString];
NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:fileURL options:0 error:&error];

if (error) {
    NSLog(@"Unable to load file from provided URL %@: %@", myString, error);
}