3

我正在使用下面显示的代码保存一个 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];
4

3 回答 3

2

如果要使用 iOS Mail 将文件作为附件发送,您需要设置文件的 MIME 类型。根据这个网站,用于 WAV 的 MIME 类型之一是音频/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];

}
于 2013-07-01T06:56:19.213 回答
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];

}
于 2013-07-01T07:14:52.367 回答
0

使用 MIME 类型,您可以按照 Tblue 的回答使用 .wav 文件。

于 2013-07-01T08:36:04.157 回答