When the microphone access to my flutter app is permanently denied, I am accessing app settings using permission_handler: 11.3.1
package’s openAppSetting()
method.
There when I allow access to the microphone the device is disconnected/crashed. And coming back to the app is restarting the app.
It works while I am requesting permission or allowing. And for anroid everything works completely fine.
In the info.plist
flie I have given permission for microphone
<key>NSMicrophoneUsageDescription</key>
<string>In order to send voice text this app requires Mic permission.</string>
In the Podfile
U have added:
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 information: 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.microphone
'PERMISSION_MICROPHONE=1',
]
end
end
end
I tried flutter clean
command and deleting podfile.lock
Here is my code:
onPressed: () {
PermissionManager().getMicrophonePermission().then((value) {
if (value.isPermanentlyDenied) {
PermissionManager().goToOpenSetting();
} else if (value.isRestricted || value.isDenied) {
PermissionManager()
.requestPermission()
.then((requestValue) {
if (requestValue.isGranted) {
_startRecording();
setState(() {
_isVoiceEnabled = !_isVoiceEnabled;
});
}
});
} else {
_startRecording();
setState(() {
_isVoiceEnabled = !_isVoiceEnabled;
});
}
});
},
The onPressed()
calls functions for PermissionManager
class:
class PermissionManager {
///
Future<PermissionStatus> getMicrophonePermission() async {
return await Permission.microphone.status;
}
Future<PermissionStatus> requestPermission() async {
return await Permission.microphone.request();
}
///
Future<void> goToOpenSetting() async {
EasyLoading.showToast(
'Please, allow microphone permission while using the app',
duration: const Duration(milliseconds: 300),
).then((value) async {
await openAppSettings();
});
}
}
Please, kindly help me finding where it is going wrong. Thanks in advance to everyone.