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
richContent: new RichContent(image: 'https://example.com/order-1234.png'),
212
+
collapseId: 'order-1234-update',
213
+
tag: 'order-1234',
214
+
);
215
+
```
216
+
144
217
The `SendNotificationsResult` object returned by `sendNotifications()` contains a collection of all the resulting
145
218
`PushTicket` objects, as well as a collection of `PushError` objects representing any
146
219
[request-level errors](https://docs.expo.dev/push-notifications/sending-notifications/#request-errors) encountered while
147
220
sending the given batch of notifications.
148
221
149
222
The `PushTicketCollection` is ordered according to the order of the `PushMessage` objects passed in to
150
223
`sendNotifications()`. Each `PushTicket` will either be a `SuccessfulPushTicket` or a `FailedPushTicket`, the latter
151
-
representing a ticket that was returned with a status of "error".
224
+
representing a ticket that was returned with a status of "error". Either can be distinguished with `$ticket->isSuccessful()`/`$ticket->isFailed()`, in addition to `instanceof`.
152
225
153
226
If errors were encountered, they will be present in the `PushErrorCollection`, and the `PushTicketCollection` will have
154
227
a gap in its keys that corresponds to the failed chunk of notifications. Inspect the errors to find out what went wrong.
155
228
229
+
`SendNotificationsResult` also provides a set of helper methods for quickly checking the outcome without inspecting
230
+
the collections directly: `hasTickets()`, `hasSuccessfulTickets()`, `hasFailedTickets()` and `hasErrors()`.
231
+
156
232
If only a single notification needs to be sent, the `sendNotification()` method can be used instead. This accepts a
157
233
single `PushMessage` and, like `sendNotifications()`, returns a `SendNotificationsResult`:
158
234
@@ -205,11 +281,50 @@ getting the given batch of receipts.
205
281
206
282
The `PushReceiptCollection` respects the order of receipts returned by the Expo Push API. To find a specific receipt in
207
283
the collection, the `getById()` method can be used. Each `PushReceipt` with either be a `SuccessfulPushReceipt` or a
208
-
`FailedPushReceipt`, the latter representing a receipt that was returned with a status of "error".
284
+
`FailedPushReceipt`, the latter representing a receipt that was returned with a status of "error". Either can be
285
+
distinguished with `$receipt->isSuccessful()`/`$receipt->isFailed()`, in addition to `instanceof`.
209
286
210
287
If errors were encountered, they will be present in the `PushErrorCollection`, and the `PushReceiptCollection` will have
211
288
a gap in its keys that corresponds to the failed chunk of notifications. Inspect the errors to find out what went wrong.
212
289
290
+
`GetReceiptsResult` also provides a set of helper methods for quickly checking the outcome without inspecting the
291
+
collections directly: `hasReceipts()`, `hasSuccessfulReceipts()`, `hasFailedReceipts()` and `hasErrors()`.
292
+
293
+
### Serialisation
294
+
295
+
`PushMessage`, `PushToken`, and every collection class (`PushMessageCollection`, `PushTokenCollection`,
296
+
`PushTicketCollection`, `PushReceiptCollection`, `PushReceiptIdCollection` and `PushErrorCollection`) can be converted
297
+
to and from arrays or JSON strings via `toJson()`/`toArray()`/`fromJson()`/`fromArray()`, which is useful for queuing
|`InvalidArgumentException`| A `PushToken` is constructed with an invalid token string, or a `PushMessage`'s `data` cannot be encoded as JSON. |
348
+
|`OverflowException`| A single `PushMessage`'s `data` field exceeds 4096 bytes once encoded. (Notification/receipt *counts* per request are chunked automatically and won't trigger this.) |
349
+
|`Saloon\Exceptions\InvalidPoolItemException`| An item yielded to the internal request pool is not a valid request — this would indicate a bug in the library. |
350
+
|`Saloon\Exceptions\Request\RequestException`| An HTTP request ultimately failed (e.g. a persistent `4xx`/`5xx` response) after all retries were exhausted, with `throwOnMaxTries` enabled (the default). |
351
+
|`Saloon\Exceptions\Request\FatalRequestException`| A network-level failure (e.g. connection refused, timeout) after all retries were exhausted, with `throwOnMaxTries` enabled (the default). |
352
+
353
+
If `throwOnMaxTries` is set to `false` on the `RetryConfig`, the last failed response is returned as a `PushError`
354
+
instead of throwing `RequestException`/`FatalRequestException`.
355
+
356
+
```php
357
+
use Dru1x\ExpoPush\ExpoPush;
358
+
use Dru1x\ExpoPush\PushMessage\PushMessage;
359
+
use Dru1x\ExpoPush\PushToken\PushToken;
360
+
use Saloon\Exceptions\Request\FatalRequestException;
361
+
use Saloon\Exceptions\Request\RequestException;
362
+
363
+
$expoPush = new ExpoPush();
364
+
365
+
try {
366
+
$result = $expoPush->sendNotification(
367
+
new PushMessage(to: new PushToken('ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]'), body: 'Hello'),
0 commit comments