我想在Flutter中添加允许通知权限提示。

huangapple go评论83阅读模式
英文:

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&lt;void&gt; 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();
   }
}

huangapple
  • 本文由 发表于 2023年6月29日 15:20:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定