Home > Blockchain >  flutter iOS can not use microphone, problem with permission_handler
flutter iOS can not use microphone, problem with permission_handler

Time:10-18

I try use microphone in my flutter app. I create method do try ask user about microphone permissions. It working on Android, but not working on iOS. Of course I add this line to info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>Used to capture audio for image picker plugin</string>

I ask about permissions using widget:

Widget allowButton() {
   return OutlinedButton(
       child: Text("ALLOW MIC"),
       onPressed: () async {
         var status = await Permission.microphone.request().then((value) {
           print("After request()");
           return value;
         });
         print(status);
         if (await Permission.microphone.request().isGranted) {
           print("OK!!!");
         } else {
           print("NOT OK!!!");
         }
       });
 } 

More information about libraries and environment:

  • permission_handler: ^8.1.6
  • flutter 2.2.2
  • IDE VSCode on MacOS 11.6
  • I try rebuild project (using "flutter clean")

In my app settings I do not see information about microphone. Of course camera and gallery access working. enter image description here

CodePudding user response:

Add PERMISSION_MICROPHONE=1 in your PodFile

Check PodFile for reference

CodePudding user response:

Thank You Kaushik Chandru, After Your suggestion I replace part of my Podfile. Old fragment:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

New fragment:



post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    target.build_configurations.each do |config|
      # You can remove unused permissions here
      # for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
      # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.calendar
        # 'PERMISSION_EVENTS=1',

        ## dart: PermissionGroup.reminders
        # 'PERMISSION_REMINDERS=1',

        ## dart: PermissionGroup.contacts
        # 'PERMISSION_CONTACTS=1',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.microphone
        'PERMISSION_MICROPHONE=1',

        ## dart: PermissionGroup.speech
        # 'PERMISSION_SPEECH_RECOGNIZER=1',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=1',

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        # 'PERMISSION_LOCATION=1',
       
        ## dart: PermissionGroup.notification
        # 'PERMISSION_NOTIFICATIONS=1',

        ## dart: PermissionGroup.mediaLibrary
        'PERMISSION_MEDIA_LIBRARY=1',

        ## dart: PermissionGroup.sensors
        # 'PERMISSION_SENSORS=1',

        ## dart: PermissionGroup.bluetooth
        # 'PERMISSION_BLUETOOTH=1',

        ## dart: PermissionGroup.appTrackingTransparency
        # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

        ## dart: PermissionGroup.criticalAlerts
        # 'PERMISSION_CRITICAL_ALERTS=1',
      ]

    end
  end
end
  • Related