2013-07-01 4 views
3

Я сохраняю wav-файл, используя приведенный ниже код. Затем я добавляю это по электронной почте. Однако он не отправляется по электронной почте. Кажется, что что-то не так в записи. Может кто-нибудь помочь, пожалуйста.Сохраните запись в формате wav в папке Documents iphone

NSArray *pathComponents = [NSArray arrayWithObjects: 
          [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], 
          @"MyAudioMemo.wav", 
          nil]; 
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents]; 

// Setup audio session 
AVAudioSession *session = [AVAudioSession sharedInstance]; 
[session setCategory:AVAudioSessionCategoryRecord error:nil]; 

// Define the recorder setting 
recordSetting = [[NSMutableDictionary alloc] init]; 

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; 
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 16] forKey:AVLinearPCMBitDepthKey]; 
[recordSetting setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsBigEndianKey]; 
[recordSetting setValue:[NSNumber numberWithBool: NO] forKey:AVLinearPCMIsFloatKey]; 
[recordSetting setValue:[NSNumber numberWithInt: AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey]; 

// Initiate and prepare the recorder 
audioRecorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL]; 
audioRecorder.delegate = self; 
audioRecorder.meteringEnabled = YES; 
[audioRecorder prepareToRecord]; 
+0

Вы проверяете каталог в папке документов вашего аудио – Purva

+1

Да, это правильно 4.3 МБ. Я думаю, что в коде есть некоторая ошибка. где и как мы можем включить, что файл является .wav? просто имя? – ScarletWitch

+0

Вы поняли? – Purva

ответ

2

Если вы хотите отправить файл в виде вложения с iOS Mail, вам необходимо установить тип файла MIME. Согласно this web site, один из MIME-типов, используемых для WAV, - аудио/wav.

- (void)mailMe { 

// recipient address 
NSString *email = mailaddress; 
NSMutableArray *toRecipient = [[NSMutableArray alloc]initWithObjects:nil]; 
[toRecipient addObject:email]; 
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
mc.mailComposeDelegate = self; 

// attachment 
NSData *data = [NSData dataWithContentsOfFile:[self filePathAudio]]; 
[mc addAttachmentData:data mimeType:@"audio/wav" fileName:@"MyAudioMemo.wav"]; 

// subject 
[mc setSubject:mailsubject]; 

// message 
[mc setMessageBody:msgbody isHTML:NO]; 

[mc setToRecipients:toRecipient]; 
[self presentViewController:mc animated:YES completion:NULL]; 

} 
+1

Спасибо. Является ли тип аудио/wav или аудио/vnd.wave типом mime, как указано в https://en.wikipedia.org/wiki/Internet_media_type ??? – ScarletWitch

1
- (void)mailPressed { 

// recipient address 

NSMutableArray *toRecipient = [[NSMutableArray alloc]initWithObjects:@"mail id here ",nil]; 

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

// attachment 
NSData *data = [NSData dataWithContentsOfFile:[self filePathAudio]]; 

[mailComposer addAttachmentData:myData mimeType:@"audio/wav" fileName:fileName] //file name is name of youw audio file 

// set subject 
[mailcmp setSubject:mailsubject]; 

// set message 
[mailcmp setMessageBody:msgbody isHTML:NO]; 

[mailcmp setToRecipients:toRecipient]; 
[self presentViewController:mailcmp animated:YES completion:NULL]; 

} 
0

Использование MIME тип вы можете использовать .wav файл в соответствии Ответ Tblue в.

Смежные вопросы