搜尋套件、儲存庫與 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!

所屬分類

原始碼儲存庫

使用此套件的專案