php-firebase-cloud-messaging
php-firebase-cloud-messaging copied to clipboard
time_to_live - how do you set it?
Hi,
Thanks for the amazing plugin, it's really helped in us implementing FCM through PHP.
I'm trying to look at a way to set 'time_to_live' through the options but can't seem to get it working through
$message->setJsonKey('time_to_live', 0);
Also i have some messages having content_available with setJsonKey, can we do
$message->setJsonKey(array("content_available" => true, "time_to_live" => 0));
??
I couldn't seem to see any reference for setJsonKey in any documentation for this repo but i know it's within FCM docs.
Thanks,
Lew.
Try this:
// Set timeouts
$log->debug("Serialized message before adding timeouts: " . json_encode($message));
$message->setJsonKey("apns", ["headers" => ["apns-expiration" => time() + self::MESSAGE_TIMEOUT_SEC]]);
$message->setJsonKey("android", ["ttl" => self::MESSAGE_TIMEOUT_SEC . "s"]);
$message->setJsonKey("webpush", ["headers" => ["TTL" => self::MESSAGE_TIMEOUT_SEC . ""]]);
$log->debug("Serialized message after adding timeouts: " . json_encode($message));