flutter iOS 无法使用麦克风,permission_handler 有问题
flutter iOS can not use microphone, problem with permission_handler
我尝试在我的 flutter 应用程序中使用麦克风。我创建方法确实尝试向用户询问麦克风权限。它适用于 Android,但不适用于 iOS。当然,我将这一行添加到 info.plist:
<key>NSMicrophoneUsageDescription</key>
<string>Used to capture audio for image picker plugin</string>
我询问使用小部件的权限:
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!!!");
}
});
}
关于图书馆和环境的更多信息:
- permission_handler: ^8.1.6
- 颤振 2.2.2
- IDE VSCode 在 MacOS 11.6
- 我尝试重建项目(使用“flutter clean”)
在我的应用程序设置中,我没有看到有关麦克风的信息。当然相机和画廊访问工作。
在您的 PodFile 中添加 PERMISSION_MICROPHONE=1
检查PodFile以供参考
谢谢 Kaushik Chandru,
根据您的建议,我替换了部分 Podfile。
旧片段:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
新片段:
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
我尝试在我的 flutter 应用程序中使用麦克风。我创建方法确实尝试向用户询问麦克风权限。它适用于 Android,但不适用于 iOS。当然,我将这一行添加到 info.plist:
<key>NSMicrophoneUsageDescription</key>
<string>Used to capture audio for image picker plugin</string>
我询问使用小部件的权限:
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!!!");
}
});
}
关于图书馆和环境的更多信息:
- permission_handler: ^8.1.6
- 颤振 2.2.2
- IDE VSCode 在 MacOS 11.6
- 我尝试重建项目(使用“flutter clean”)
在我的应用程序设置中,我没有看到有关麦克风的信息。当然相机和画廊访问工作。
在您的 PodFile 中添加 PERMISSION_MICROPHONE=1
检查PodFile以供参考
谢谢 Kaushik Chandru, 根据您的建议,我替换了部分 Podfile。 旧片段:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
新片段:
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