Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Vanethos/flutter_notification_permissions
Plugin for Flutter to check and ask for Notification Permissions
https://github.com/Vanethos/flutter_notification_permissions
Last synced: 13 days ago
JSON representation
Plugin for Flutter to check and ask for Notification Permissions
- Host: GitHub
- URL: https://github.com/Vanethos/flutter_notification_permissions
- Owner: Vanethos
- License: bsd-2-clause
- Created: 2019-03-01T08:26:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T02:46:39.000Z (7 months ago)
- Last Synced: 2024-08-01T16:26:34.259Z (3 months ago)
- Language: Dart
- Size: 4.35 MB
- Stars: 81
- Watchers: 4
- Forks: 61
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flutter Notification Permissions
Package to check for and ask for Notification Permissions on iOS and Android.## Checking Notification Permission Status
```dart
Future permissionStatus =
NotificationPermissions.getNotificationPermissionStatus();
```This method will return an enum with the following values:
```dart
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:
```dart
Future 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](https://stackoverflow.com/a/53453243/4499889) in order to solve the issue:
```
'notification_permissions/notification_permissions-Swift.h' file not found
#import
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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](https://github.com/fedecastelli) for helping me in the Swift Code!