我尝试录制音频并将其保存到文档文件夹,但该程序只能在模拟器中工作。一旦我在我的iPhone(ios 8.3)中运行它,它就无法工作。我的代码有问题吗?谢谢。
这是h文件:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <AVFoundation/AVAudioRecorder.h>
#import <Accelerate/Accelerate.h>
@interface ViewController : UIViewController{
AVAudioPlayer *player;
AVAudioRecorder *recorder;
}
- (IBAction)REC:(id)sender;
- (IBAction)STOP_and_SAVE:(id)sender;
- (IBAction)PLAY:(id)sender;
@property (nonatomic, strong) NSString *Record_path1_string;
@end
m file:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)REC:(id)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
self.Record_path1_string = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bbb.wav"];
recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath: self.Record_path1_string] settings:nil error:nil];
[recorder prepareToRecord];
[recorder record];
NSLog(@"recording!");
}
- (IBAction)STOP_and_SAVE:(id)sender {
[recorder stop];
}
- (IBAction)PLAY:(id)sender {
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: self.Record_path1_string] error:nil];
[player play];
}
@end
我已经检查了Mac中模拟器中的Documents文件夹,音频文件已保存,但我无法检查iPhone中的Documents文件夹。