Skip to content

Commit 9a8aaef

Browse files
committed
docs: update permission section in PushNotifications documentation
1 parent ccdd598 commit 9a8aaef

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

PushNotifications.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,47 @@ import ably_flutter
185185
- Your device is now ready to receive and display user notifications (called alert notifications on iOS and notifications on Android) to the user, when the application is in the background.
186186
- For debugging: You could use the Ably dashboard (notification tab) or the Push Admin API using another SDK to ensure the device has been subscribed by listing the subscriptions on a specific channel. Alternatively, you can list the push channels the device or client is subscribed to: `final subscriptions = channel.push.listSubscriptions()`. This API requires Push Admin capability, and should be used for debugging. This means you must use an Ably API key or token with the `push-admin` capability.
187187

188-
### Notification Permissions (iOS only)
188+
### Notification Permissions
189+
190+
SDK users are free to choose any library they prefer for managing device permissions, allowing flexibility based on their project requirements.
191+
192+
#### Notification Permissions using `permission_handler` package
193+
194+
However, we recommend using the [flutter-permission-handler](https://github.com/baseflow/flutter-permission-handler) package due to its reliable cross-platform support for both iOS and Android.
195+
196+
> [!NOTE]
197+
> Requesting notification permissions is only necessary for Android 13 (API level 33) and above. For earlier Android versions, notification permissions are granted by default.
198+
199+
To implement it in your app, follow these steps:
200+
201+
1. Add `permission_handler` to your `pubspec.yaml` dependencies.
202+
2. Use `Permission.notification.request()` to request notification permissions across both iOS and Android.
203+
204+
Example using `permission_handler`:
205+
206+
```dart
207+
import 'package:permission_handler/permission_handler.dart';
208+
209+
// Request notification permission
210+
PermissionStatus status = await Permission.notification.request();
211+
212+
if (status.isGranted) {
213+
// Handle permission granted
214+
} else {
215+
// Handle permission denied
216+
}
217+
```
218+
219+
#### Built-in Notification Permissions managment (iOS only)
220+
221+
> [!WARNING]
222+
> **Deprecation Notice:**
223+
>
224+
> This approach to requesting notification permissions is deprecated for two key reasons:
225+
>
226+
> 1. **Platform Limitation:** The `Push#requestPermission` method only works for iOS and does not support Android, which means developers have to rely on platform-specific code.
227+
>
228+
> 2. **Client Initialization Dependency:** The `requestPermission` method is tied to the Ably Push object, which requires an initialized Ably client to request permissions. This is not an ideal design, as permission requests should not depend on initializing the Ably client. Instead, permission handling should be a standalone utility function.
189229
190230
Requesting permissions:
191231

@@ -208,6 +248,12 @@ if (Platform.isIOS) {
208248
}
209249
```
210250

251+
> [!NOTE]
252+
> We are currently working on adding built-in support for notification permissions as a utility function within our SDK.
253+
> This update will simplify permission handling and provide a unified solution for both iOS and Android.
254+
> You can subscribe to [the issue](https://github.com/ably/ably-flutter/issues/545) to receive updates on our progress.
255+
> Once implemented, using third-party libraries like flutter-permission-handler will be optional for managing notification permissions.
256+
211257
### Sending Messages
212258

213259
#### Notification Message / Alert Push Notification

0 commit comments

Comments
 (0)