在后台线程中保存未完成
Saving in Background Thread not getting finished
我有一个 AVAudioRecorder
的实例,我注意到当用户关闭应用程序的速度过快且录制内容较大时,文件无法正确保存。
当我在主线程中调用 [recorderObject stop]
并且文件保存在本地时,甚至会发生这种情况。
我也试过在录制停止后移动文件(在 (void)audioRecorderDidFinishRecording:successfully:
方法中)。但是我注意到,当我在具有 high
优先级的后台线程中使用 NSFileManager
进行移动时,它也并不总是完成。
有什么方法可以确保文件得到保存,即使用户在完成较长的录制后不久就退出了应用程序?
谢谢
查看 Apple's documentation 在后台执行任务。
Apps moving to the background are expected to put themselves into a
quiescent state as quickly as possible so that they can be suspended
by the system. If your app is in the middle of a task and needs a
little extra time to complete that task, it can call the
beginBackgroundTaskWithName:expirationHandler:
or
beginBackgroundTaskWithExpirationHandler:
method of the UIApplication
object to request some additional execution time. Calling either of
these methods delays the suspension of your app temporarily, giving it
a little extra time to finish its work. Upon completion of that work,
your app must call the endBackgroundTask: method to let the system
know that it is finished and can be suspended.
我有一个 AVAudioRecorder
的实例,我注意到当用户关闭应用程序的速度过快且录制内容较大时,文件无法正确保存。
当我在主线程中调用 [recorderObject stop]
并且文件保存在本地时,甚至会发生这种情况。
我也试过在录制停止后移动文件(在 (void)audioRecorderDidFinishRecording:successfully:
方法中)。但是我注意到,当我在具有 high
优先级的后台线程中使用 NSFileManager
进行移动时,它也并不总是完成。
有什么方法可以确保文件得到保存,即使用户在完成较长的录制后不久就退出了应用程序?
谢谢
查看 Apple's documentation 在后台执行任务。
Apps moving to the background are expected to put themselves into a quiescent state as quickly as possible so that they can be suspended by the system. If your app is in the middle of a task and needs a little extra time to complete that task, it can call the
beginBackgroundTaskWithName:expirationHandler:
orbeginBackgroundTaskWithExpirationHandler:
method of theUIApplication
object to request some additional execution time. Calling either of these methods delays the suspension of your app temporarily, giving it a little extra time to finish its work. Upon completion of that work, your app must call the endBackgroundTask: method to let the system know that it is finished and can be suspended.