我正在使用下面显示的代码保存wav文件。然后我将其添加到电子邮件中。但是,它不是通过电子邮件发送的。录音中似乎有问题。任何人都可以帮忙。
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 :(得分:2)
如果要将文件作为附件发送到iOS Mail,则需要设置文件的MIME类型。根据{{3}},用于WAV的一种MIME类型是audio / 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 :(得分: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];
}
答案 2 :(得分:0)
使用MIME类型,您可以根据Tblue的答案使用.wav文件。