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 メールでファイルを添付して送信するには、ファイルの MIME タイプを設定する必要があります。この Web サイトによると、WAV に使用される MIME タイプの 1 つが 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];

}
于 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 に答える