英文:
I want add allow notification permission prompt in flutter
问题
I want to ask the user this type of prompt in both the Android and iOS when the user comes inside my app. But I'm not able to achieve it. So if someone knows, please help me with this. Thank you in advance.
英文:
enter image description here
I want to ask the user this type of promt in both the android and ios ,when the user come inside my app. But im not able to achive it.
So if some one know please help me with this. Thank you in advance.
答案1
得分: 1
使用 permision_handler 包的方式如下:
Future<void> requestNotificationPermissions() async {
final PermissionStatus status = await Permission.notification.request();
if (status.isGranted) {
// 通知权限已授予
} else if (status.isDenied) {
// 通知权限已拒绝
} else if (status.isPermanentlyDenied) {
// 通知权限已永久拒绝,请打开应用程序设置
await openAppSettings();
}
}
英文:
use the permision_handler package like this:
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();
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论