rmbrone / flutter_audio_recorder

Flutter plugin that can support audio recording and level metering
MIT License
119 stars 150 forks source link

New iOS error: Unexpectedly found nil while unwrapping an Optional value #30

Open herrmayr opened 4 years ago

herrmayr commented 4 years ago

In the latest build of my app, without making any changes to the part where the app uses flutter_audio_recorder, the app crashes when trying to start a recording.

Here is the error:

.wav /var/mobile/Containers/Data/Application/C35343CA-6921-4411-B589-3ACA6427E5DD/Library/Application Support/temp_voicerecording.wav Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/......./development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_audio_recorder-0.5.5/ios/Classes/SwiftFlutterAudioRecorderPlugin.swift, line 75

In Xcode, the debugger jumps to this line:

audioRecorder = try AVAudioRecorder(url: URL(string: mPath)!, settings: settings) with the error

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Since I haven't changed anything around the audio recorder implementation, I suspect a new bug regarding iOS with this package? Android works fine by the way...

Of course, I might have made a mistake I'm currently anaware of - any hints would be greatly appreciated!

herrmayr commented 4 years ago

I found the root of the problem, but I don't have a fix: When the path contains a space, the error I mentioned above appears.

The iOS path to the app's temp folder does contain a path since it's called "Application Support", so I can only hot-fix this issue by using the app's user-visible documents folder, which is not ideal ...

DitoHI commented 4 years ago

Thanks for pointing the cause of the problem. While waiting the library fixes this problem, I remove any space in the first argument of FlutterAudioRecorder.

The temporary fix such as:

var fileDir = 'example name of file';
var recorder = FlutterAudioRecorder(
   '$fileDir.wav'.replaceAll(' ', ''),
   audioFormat: AudioFormat.WAV,
);