搜索插件、代码仓与 APP 分类

插件详情v0.6.1

notification_permissions

一个用于在 Android 和 iOS 上检查和请求通知权限的插件

AndroidiOS
近 30 天下载
1340
喜欢数
117
Pub 分数
120

安装插件

flutter pub add notification_permissions

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

notification_permissions 包提供了一种简单的方法,可在 Android 和 iOS 平台上检查和请求通知权限。它使应用程序能够确定当前的权限状态,并提示用户授予或拒绝通知,确保符合平台特定的要求。该插件轻量且可无缝集成到 Flutter 应用中,支持运行时检查和用户交互流程。它帮助开发者负责任地管理通知访问权限,并通过在适当的时间引导用户完成权限请求,提升用户体验。

适合场景

  • 检查当前通知权限状态
  • 向用户请求通知权限
  • 在应用逻辑中处理权限响应
  • 确保符合平台指南
  • 通过及时通知提升用户参与度

主要特点

  • 对 Android 和 iOS 的跨平台支持
  • 用于检查和请求权限的简单 API
  • 支持异步权限处理
  • 提供清晰的权限状态
  • 所需的最小样板代码

适合对象

  • 需要推送通知的应用
  • 需要权限指导的面向用户的应用程序
  • 开发注重隐私功能的开发者
  • Flutter 应用针对两个移动平台
  • 强调用户同意和透明度的项目

使用建议

  • 需要正确处理权限被拒绝的情况
  • 可能会触发影响用户流程的系统对话框
  • 在每个平台上没有正确的应用配置则无法使用
  • 仅限通知权限(不包括其他类型)
  • 由于操作系统级别的行为,需要在实际设备上进行测试

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Notification Permissions

Package to check for and ask for Notification Permissions on iOS and Android.

Checking Notification Permission Status

Future<PermissionStatus> permissionStatus =
    NotificationPermissions.getNotificationPermissionStatus();

This method will return an enum with the following values:

enum PermissionStatus {
  provisional, // iOS Only
	granted,
	unknown,
	denied
}

In iOS, a permission is unknown when the user hasn’t accepted or refuse the notification permissions. In Android this state will never occur, since the permission will be granted by default and it will be denied if the user goes to the app settings and turns off notifications for the app. The provisional status will also offer the same behavior.

Requesting Notification Permissions

If the PermissionStatus is denied or unknown, we can ask the user for the Permissions:

Future<PermissionStatus> permissionStatus = NotificationPermissions.requestNotificationPermissions({NotificationSettingsIos iosSettings, bool openSettings});

On Android, if the permission is denied, this method will open the app settings.

In iOS, if the permission is unknown or provisional, it will show an alert window asking the user for the permission. On the other hand, if the permission is denied it has the same behaviour as Android, opening the app settings. Also in iOS if you set openSettings to false settings window won't be opened. You will get denied status. NotificationPermissions.requestNotificationPermissions returns status after user select answer from native permission popup.

Note: if the permission is granted, this method will not do anything.

iOS Error: Swift.h not found

If your project is in Objective-C, you will have to do the changes referenced in this SO post in order to solve the issue:

'notification_permissions/notification_permissions-Swift.h' file not found
    #import <notification_permissions/notification_permissions-Swift.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

Add use_frameworks! in target Runner in your (YOUR_PROJECT)/ios/Podfile

target 'Runner' do
  use_frameworks! # Add here

Special Thanks

Special thanks to fedecastelli for helping me in the Swift Code!

所属分类

源码仓库

使用此插件的项目