diff --git a/src/Payload/Alert.php b/src/Payload/Alert.php index d7e6a41..48094db 100644 --- a/src/Payload/Alert.php +++ b/src/Payload/Alert.php @@ -30,6 +30,11 @@ class Alert implements \JsonSerializable const ALERT_LOC_ARGS_KEY = 'loc-args'; const ALERT_LAUNCH_IMAGE_KEY = 'launch-image'; + /** + * Backward compatibility w/ binary APNs protocol -- if used, all other properties are ignored and alert in payload is a string. + */ + private string $simpleAlert; + /** * A short string describing the purpose of the notification. * @@ -102,6 +107,13 @@ public static function create() return new self(); } + public function setSimpleAlert(string $text): self + { + $this->simpleAlert = $text; + + return $this; + } + /** * Set Alert title. * @@ -325,8 +337,12 @@ public function toJson(): string * @return array * @link http://php.net/manual/en/jsonserializable.jsonserialize.php */ - public function jsonSerialize(): array + public function jsonSerialize(): array|string { + if (!empty($this->simpleAlert)) { + return $this->simpleAlert; + } + $alert = []; if (is_string($this->title)) {