2016-08-30 65 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方法相應

相關問題