[英]ios , Attach Audio file aac format to Email
i try to send a audio record by file aac (kAudioFormatMPEG4AAC) format but the file attached it's doesn't send 我尝试通过文件AAC(kAudioFormatMPEG4AAC)格式发送音频记录,但附件中的文件未发送
*myString = file://localhost/private/var/mobile....... * myString = file://本地主机/专用/ var /移动.......
here is my code 这是我的代码
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];
NSData *data = [NSData dataWithContentsOfFile:path];
You're passing in a file://
URL, which won't be understood by that method. 您正在传递
file://
URL,该方法将无法理解该URL。 That method expects just a standard file path, ie /private/var/mobile/
. 该方法只需要一个标准文件路径,即
/private/var/mobile/
。
You could simply use the file path, but if you're only provided with a URL form string, you can create a URL object and use that with NSData. 您可以简单地使用文件路径,但是如果仅提供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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.