title: Get AVAudio Recording URL Before App is Terminated
body: <p>I've played with several recording apps and when I swipe to dismiss/terminate while recording, when I come back to the app the audio that was recording prior to the app begin terminated, is available for me to listen to. From my understanding that audio is only available via <code>audioRecorderDidFinishRecording</code>.</p>
  <p>In my app I tried to do the same. If a user is recording audio and the app is suddenly terminated (they swipe it away), I stop the recording. But in the delegate <code>audioRecorderDidFinishRecording</code>
  I can't seem to get the <code>url</code>.</p>
  <p>When the app is terminated the <a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate" rel="nofollow noreferrer">docs</a> says we have 5 seconds</p>
  <blockquote>
  <p>Your implementation of this method has approximately five seconds to
  perform any tasks and return. If the method does not return before
  time expires, the system may terminate the process altogether.</p>
  </blockquote>
  <p>The <code>url</code> usually returns way before 5 seconds but for some reason the recording delegate is never reached. What's the issue? In the example below steps 2 or 5 never get reached.</p>
  <pre><code>NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminate(notification:)),
                                                 name: UIApplication.willTerminateNotification,
                                                 object: nil)
  
  @objc func applicationWillTerminate(notification: Notification) {
  
       if let micRecorder = micRecorder, micRecorder.isRecording {
  
           micRecorder.stop() // 1. stop recording
       }
  }
  
  func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
  
      // 2. print(&quot;if successful the url should be returned&quot;)
  
      if flag {
  
          let url = recorder.url
  
          // 3. save url to FileManager then to CoreData
  
      } else {
  
          // 4. something went awry
      }
  }
  
  func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) {
  
      // 5. print(&quot;something went wrong&quot;)
  
      print(error.localizedDescription)
  }
  </code></pre>