0

我嘗試通過文件AAC發送錄音(kAudioFormatMPEG4AAC)格式,但附加的文件,它不會發送IOS,附加音頻文件AAC格式到電子郵件

* MyString的=文件://本地主機/私營/ VAR /移動.......

這裏是我的代碼

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
NSData *data = [NSData dataWithContentsOfFile:path]; 

你傳遞一個file:// 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); 
}