我正在尝试展示一个弹出窗口来请求通知权限。我已经尝试使用permission_handler
库,但对于通知和蓝牙,它将不会显示对话框。是否有其他方法展示对话框以请求通知权限?
我正在尝试展示一个弹出窗口来请求通知权限。我已经尝试使用permission_handler
库,但对于通知和蓝牙,它将不会显示对话框。是否有其他方法展示对话框以请求通知权限?
Future<void> requestNotificationPermissions() async {
final PermissionStatus status = await Permission.notification.request();
if (status.isGranted) {
// Notification permissions granted
} else if (status.isDenied) {
// Notification permissions denied
} else if (status.isPermanentlyDenied) {
// Notification permissions permanently denied, open app settings
await openAppSettings();
}
}
在Podfile
中,我将需要使用的权限的值从0
改为1
。例如:
...
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
# YOUR CUSTOM TARGET CODE HERE.
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
'PERMISSION_EVENTS=0',
## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
## dart: PermissionGroup.bluetooth
'PERMISSION_BLUETOOTH=1',
]
end
end
end
在android -> app -> build.gradle
中,我将targetSdkVersion
设置为33
。例如:
...
android {
...
defaultConfig {
...
minSdkVersion 21 // flutter.minSdkVersion
targetSdkVersion 33 // flutter.targetSdkVersion
...
}
...
}
...