audio_recorder icon indicating copy to clipboard operation
audio_recorder copied to clipboard

Error: 'AVAudioSessionCategoryOptions' has been renamed to 'AVAudioSession.CategoryOptions' with: AVAudioSessionCategoryOptions.defaultToSpeaker)

Open AteqEjaz opened this issue 5 years ago • 11 comments

Hi Guys,

Using latest version of Audio_recorder plugin and it is not working on IOS, i have target ios version(10), Any thoughts?

Xcode's output: ↳ === BUILD TARGET sqflite OF PROJECT Pods WITH CONFIGURATION Debug === /Users/user/flutter-dev/flutter/.pub-cache/hosted/pub.dartlang.org/audio_recorder-1.0.1/ios/Classes/SwiftAudioRecorderPlugin.swift:40:23: error: 'AVAudioSessionCategoryOptions' has been renamed to 'AVAudioSession.CategoryOptions' with: AVAudioSessionCategoryOptions.defaultToSpeaker) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AVAudioSession.CategoryOptions AVFoundation.AVAudioSessionCategoryOptions:2:18: note: 'AVAudioSessionCategoryOptions' was obsoleted in Swift 4.2 public typealias AVAudioSessionCategoryOptions = AVAudioSession.CategoryOptions ^ /Users/user/flutter-dev/flutter/.pub-cache/hosted/pub.dartlang.org/audio_recorder-1.0.1/ios/Classes/SwiftAudioRecorderPlugin.swift:68:68: error: cannot call value of non-function type 'AVAudioSession.RecordPermission' switch AVAudioSession.sharedInstance().recordPermission(){ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Could not build the application for the simulator. Error launching application on iPhone Xʀ.

AteqEjaz avatar Sep 03 '19 22:09 AteqEjaz

Not a working solution but if you want your build to build you can change

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSession.CategoryOptions.defaultToSpeaker) to try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.defaultToSpeaker);

lucygeneric avatar Sep 18 '19 00:09 lucygeneric

Had the same issue resolved by @lucygeneric mentioned;

DyaryRaoof avatar Dec 11 '19 19:12 DyaryRaoof

also change this line
switch AVAudioSession.sharedInstanc.recordPermission(){ case AVAudioSession.RecordPermission.granted: to switch AVAudioSession.sharedInstance().recordPermission{ case AVAudioSession.RecordPermission.granted:

to resolve the other error

DyaryRaoof avatar Jan 03 '20 18:01 DyaryRaoof

@DyaryRaoof any work around this issue ?

devhci avatar Apr 14 '20 05:04 devhci

I tried the solutions @DyaryRaoof and @lucygeneric wrote but now when I click the start record button my entire application just crashes...if anyone could help it would be greatly appreciated

LarrySimiyu avatar Jun 05 '20 20:06 LarrySimiyu

what error do you get when it crashes ? have you tried flutter run --verbose to see the error message ?

DyaryRaoof avatar Jun 05 '20 21:06 DyaryRaoof

@DyaryRaoof @LarrySimiyu , Hi Dyaru , I have followed all the changes mentioned , but My app is crashing too, here the error, please let me know how can I solve this issue.

Flutter Output : Fatal error: Unexpectedly found nil while unwrapping an Optional value: file audio_recorder/SwiftAudioRecorderPlugin.swift, line 42 Lost connection to device.

Line 42 SwiftAudioRecorderPlugin.swift - audioRecorder = try AVAudioRecorder(url: URL(string: mPath)!, settings: settings)

Full Block Code -

do { try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.defaultToSpeaker);
try AVAudioSession.sharedInstance().setActive(true)

--------> audioRecorder = try AVAudioRecorder(url: URL(string: mPath)!, settings: settings) audioRecorder.delegate = self audioRecorder.record() } catch { print("fail") result(FlutterError(code: "", message: "Failed to record", details: nil)) }

And as per the suggestions in github I have made below changes,

@DyaryRaoof

also change this line switch AVAudioSession.sharedInstanc.recordPermission(){ case AVAudioSession.RecordPermission.granted: to switch AVAudioSession.sharedInstance().recordPermission{ case AVAudioSession.RecordPermission.granted:

@lucygeneric

Not a working solution but if you want your build to build you can change

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSession.CategoryOptions.defaultToSpeaker) to try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.defaultToSpeaker);

MrudulAddipalli avatar Jun 07 '21 14:06 MrudulAddipalli

Hi. I haven't used the plugin in a while. I am surprised they haven't yet fixed the issue.

Your error shows that "unexpectedly found nill while unwrapping optional" . It means the value that that that line depends on is null. Probably you don't get the permission to use the microphone , either haven't added the necessary line in info.plist or you need to use permission_handler package to get permission to use the mic before start recording.

Also try changing this line Line 42 SwiftAudioRecorderPlugin.swift - audioRecorder = try AVAudioRecorder(url: URL(string: mPath)!, settings: settings)

Remove the ! After mPath)

Also look at the plugin in Xcode it will show you errors and will try to give suggestions to fox the error in the after you run the app.

Hope this helps.

DyaryRaoof avatar Jun 07 '21 15:06 DyaryRaoof

Hi @DyaryRaoof , yes I have permission handler, and also Microphone is allowed in App Settings,

after changing the ! , I am getting below error for the same,

d/ios/Classes/SwiftAudioRecorderPlugin.swift:42:58: error: value of optional type 'URL?' must be unwrapped to a value of type 'URL' audioRecorder = try AVAudioRecorder(url: URL(string: mPath), settings: settings)

I am testing on emulator , is it because of that I am using Emulator Audio Recording is not working

MrudulAddipalli avatar Jun 07 '21 16:06 MrudulAddipalli

Probably. I am not sure.

DyaryRaoof avatar Jun 07 '21 17:06 DyaryRaoof

Hi , im having the same issue i tried the above solution.After change it the xcode build done correctly but giving errors in xcode output.I'm using an ios emulator could that be the problem? Do we need a physical device to test these?

/Users/user/flutter/.pub-cache/hosted/pub.dartlang.org/audio_recorder-1.0.2/ios/Classes/SwiftAudioRecorderPlugin.swift:42:58: error: value of optional type 'URL?' must be unwrapped to a value of type 'URL' audioRecorder = try AVAudioRecorder(url: URL(string: mPath), settings: settings)

DKsanjana avatar Jan 19 '22 06:01 DKsanjana