You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just as you can send push notifications through the Ably CLI or dashboard, you can also send them directly from your app using `deviceId`, `clientId`, or channel publishing methods. Add the following methods to `_PushHomePageState`:
459
+
The `ably_flutter` SDK does not implement the Push Admin API, so sending push directly to a `deviceId` or `clientId` from a Flutter client is not supported. Use the [Ably REST API](/docs/api/rest-sdk) from your backend server for direct push.
459
460
460
-
<Code>
461
-
```flutter
462
-
Future<void> _sendPushToDevice() async {
463
-
try {
464
-
final device = await AblyService().realtime.device();
465
-
await AblyService().realtime.push.admin.publish(
466
-
{'deviceId': device.id},
467
-
{
468
-
'notification': {
469
-
'title': 'Push Tutorial',
470
-
'body': 'Hello from device ID!',
471
-
},
472
-
'data': {'foo': 'bar', 'baz': 'qux'},
473
-
},
474
-
);
475
-
_updateStatus('Push sent to device ID: ${device.id}');
476
-
} catch (e) {
477
-
_updateStatus('Failed to send push to device: $e');
478
-
}
479
-
}
480
-
481
-
Future<void> _sendPushToClient() async {
482
-
try {
483
-
final clientId = AblyService().realtime.auth.clientId;
484
-
await AblyService().realtime.push.admin.publish(
485
-
{'clientId': clientId},
486
-
{
487
-
'notification': {
488
-
'title': 'Push Tutorial',
489
-
'body': 'Hello from client ID!',
490
-
},
491
-
'data': {'foo': 'bar', 'baz': 'qux'},
492
-
},
493
-
);
494
-
_updateStatus('Push sent to client ID: $clientId');
495
-
} catch (e) {
496
-
_updateStatus('Failed to send push to client: $e');
497
-
}
498
-
}
499
-
```
500
-
</Code>
501
-
502
-
Sending to a channel is just publishing a message with a `push``extras` field:
461
+
From the Flutter app itself, send push by publishing a message to a channel with a `push``extras` field. Any device subscribed to that channel (via Step 3) will receive the notification. Add the following method to `_PushHomePageState`:
503
462
504
463
<Code>
505
464
```flutter
506
465
Future<void> _sendPushToChannel() async {
507
466
try {
508
467
final channel = AblyService().realtime.channels.get(_channelName);
0 commit comments