0

我尝试通过文件 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];
4

1 回答 1

1
NSData   *data = [NSData dataWithContentsOfFile:path];

您正在传递一个file://URL,该方法无法理解该 URL。该方法只需要一个标准文件路径,即/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);
}
于 2013-02-05T15:58:16.577 回答