【发布时间】:2014-02-18 05:36:43
【问题描述】:
我创建了一个应用程序,该应用程序基于我阅读的内容并录制音频,然后尝试通过其唯一 url 路径将所有音频文件永久保存到 mutablearray 并从那里保存到 NSUserDefaults 但我正在尝试设置非属性列表对象错误。这是我的代码崩溃的部分:
-(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder successfully:(BOOL)flag{
if(flag==true){
[self.recordings addObject:_audioRecorder.url];
NSLog(@"prwti einai edw %@", self.recordings);
[self.userDefaults setObject:self.recordings forKey:FTS];
[self.userDefaults synchronize];
NSLog(@"%@", self.recordings);
}}
有什么建议吗?请现在我是 iOS 编程的新手并试图解决问题。谢谢。
- (void)viewDidLoad{
[super viewDidLoad];
// get the NSUserDefaults object for the app
self.userDefaults = [NSUserDefaults standardUserDefaults];
// get NSDictionary of the app's tag-query pairs
NSArray *dictionary = [self.userDefaults arrayForKey:FTS];
// if dictionary is nil, create empty NSMutableDictionary;
// otherwise, create NSMutableCopy of dictionary
if (dictionary == nil)
self.recordings = [[NSMutableArray alloc] init];
else
self.recordings = [dictionary mutableCopy];
//na allaxoume to onoma tou arxeio se monadiko gia to kathena
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"ddMMMYY_hhmmssa";
NSString *date=[[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".caf"];
_playButton.enabled = NO;
_stopButton.enabled = NO;
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:date];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16], AVEncoderBitRateKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
_audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL
settings:recordSettings
error:&error];
_audioRecorder.delegate=self;
if (error) {
NSLog(@"error: %@", [error localizedDescription]); }
else {
[_audioRecorder prepareToRecord];
}}
【问题讨论】:
标签: avfoundation nsuserdefaults avaudiorecorder avaudiosession