2016-08-30 66 views
0

我正在#iOS中创建应用程序,用户可以使用应用程序记录他的消息。现在我想将这条消息保存在数据库中并检索它,以便其他用户也可以收听此消息。iOS应用程序在数据库中保存语音笔记

现在我保存它是这样的:

//audio file save 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"audioFile.aac"]; // Where ext is the audio format extension you have recorded your sound 
[player.data writeToFile:filePath atomically:YES] 

我可以在本地保存的文件。我如何保存它,以便其他用户可以通过应用程序访问它?

如何将iPhone上生成的语音笔记保存到远程数据库?

+0

你可以用cloudkit做到这一点。 –

+0

您必须将语音笔记上载到服务器 – rafaperez

回答

0

您可以使用NSData存储您的语音音频或保存在本地,请参阅下面的代码。

NSData *audioData = [NSData dataWithContentsOfURL:recorder.url]; 
[[NSUserDefaults standardUserDefaults] setValue:audioData forKey:@"reccordingAudio"]; 

检索和播放。

NSData *audioData = [[NSUserDefaults standardUserDefaults] valueForKey:@"reccordingAudio"]; 
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:audioData error:nil]; 
[player setDelegate:self]; 
[player play]; 

注:实现AVAudioPlayerDelegate方法相应

相关问题