Agora cannot record call with iOS Swift

I am following the doc here: https://docs.agora.io/en/Voice/rtc_recording_apple?platform=iOS and implementing a basic recording. This is my code:

    func startRecording(){
        let filename = getDocumentsDirectory().appendingPathComponent("\(APP_NAME)\(now()).WAV")
        let str = String(describing: filename)
        self.recordingPath = str
        agoraKit?.startAudioRecording(str, quality: .high)
    }


    func stopRecording(){
     
        agoraKit?.stopAudioRecording()
        
        // get audio file
        guard let audioUrl = URL(string: self.recordingPath) as? URL else { return }
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0 ) { [weak self] in

            // getdata
            do {
                let myData = try Data(contentsOf: audioUrl)
                print(myData.count, myData)
            } catch {
                print(error)
            }

        }        

    }
    
private func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}

But I am getting error: The file “Whisper1608949569.WAV” couldn’t be opened because there is no such file

Full message:

file:///var/mobile/Containers/Data/Application/1F682ABD-153C-4DFD-BFF4-

02C1CE6F9A4C/Documents/Whisper1608949569.WAV
Error Domain=NSCocoaErrorDomain Code=260 "The file “Whisper1608949569.WAV” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/1F682ABD-153C-4DFD-BFF4-02C1CE6F9A4C/Documents/Whisper1608949569.WAV, NSUnderlyingError=0x281e33f60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Am I not accessing the file correctly?

This is how I have initialized the agora client:

    self.agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: AppID, delegate: self)
    agoraKit?.delegate = self
    agoraKit?.enableWebSdkInteroperability(true)

    // sample loudest speaker every second
    agoraKit?.enableAudioVolumeIndication(1000, smooth: 3, report_vad: true)

    agoraKit?.enableAudio()
    
    // config for livecast to start
    agoraKit?.setChannelProfile(.liveBroadcasting)
    
    // set framrate and HD/SD
    agoraKit?.setVideoEncoderConfiguration( CONFIG_PRODUCTION )
    
    //agoraKit?.setDefaultAudioRouteToSpeakerphone(true)

I just checked out the documentation referenced from the doc you're using and it says the method startAudioRecording(filepath, quality: quality) is now deprecated, and you should instead use this method with the additional sampleRate parameter:

https://docs.agora.io/en/Voice/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/startAudioRecording:sampleRate:quality:

Also check that the returned value of startAudioRecording and stopAudioRecording returns 0, meaning success.