【问题标题】:iOS app saving voice notes in databaseiOS应用程序将语音笔记保存在数据库中
【发布时间】:2017-01-06 21:31:30
【问题描述】:

我正在#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 上生成的语音笔记保存到远程数据库??

【问题讨论】:

  • 你可以用 cloudkit 做到这一点。
  • 您必须将语音笔记上传到服务器

标签: ios objective-c iphone voice-recording


【解决方案1】:

您可以使用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方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2021-04-12
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多