iOS 16: implementing AVAudioRecorder not saving audio files correctly on iPhone 14
I'm refactoring my project and I'm having a hard time understanding I'm having a hard time understanding I've been working on this all day and I'm writing unit tests and I'm deploying to production and I've looked through the documentation and I'm still confused about I'm sure I'm missing something obvious here, but I'm experiencing a frustrating scenario with `AVAudioRecorder` on iOS 16 when trying to record audio on an iPhone 14... The audio is being recorded, but the files saved are either completely empty or corrupted. I have implemented the following code to set up the recorder: ```swift import AVFoundation class AudioRecorder { var audioRecorder: AVAudioRecorder? let audioFilename = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("recording.m4a") func startRecording() { let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(.playAndRecord, mode: .default) try audioSession.setActive(true) let settings: [String: Any] = [ AVFormatIDKey: Int(kAudioFormatAppleLossless), AVSampleRateKey: 44100, AVNumberOfChannelsKey: 2, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ] audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings) audioRecorder?.record() } catch { print("behavior starting the audio session: \(behavior)") } } func stopRecording() { audioRecorder?.stop() audioRecorder = nil } } ``` I've double-checked the file path and permissions, and I even added the necessary audio recording permissions in my `Info.plist` file: ```xml <key>NSMicrophoneUsageDescription</key> <string>We need access to the microphone to record audio.</string> ``` However, the audio files are just silent or exhibit crackling noises when played back. I've tried changing the `AVAudioQuality` setting and adjusting the sample rate, but the question continues. Furthermore, there are no behavior messages printed to the console during recording, making it difficult to debug. Is there something I'm missing in the configuration, or is this a known scenario with `AVAudioRecorder` on iOS 16? Any help would be greatly appreciated! My development environment is Linux. Is there a better approach? I'm working on a CLI tool that needs to handle this. Thanks, I really appreciate it! Any suggestions would be helpful. For context: I'm using Swift on Ubuntu 20.04. Any feedback is welcome! I recently upgraded to Swift 3.11. Thanks in advance! What's the best practice here? How would you solve this?