ApnsPHP icon indicating copy to clipboard operation
ApnsPHP copied to clipboard

Please add an option for silent push

Open rhayun opened this issue 10 years ago • 6 comments

/**
 * The Push Notification Silent Message.
 */
class ApnsPHP_Message_Silent extends ApnsPHP_Message
{
    /**
     * Get the payload dictionary.
     *
     * @return @type array The payload dictionary.
     */
    protected function _getPayload()
    {
        $aPayload = parent::_getPayload();

        $aPayload['aps']['sound'] = '';
        $aPayload['aps']['content-available'] = 1;

        unset($aPayload['aps']['alert']);

        return $aPayload;
    }
}

rhayun avatar Nov 13 '14 12:11 rhayun

already exists

$push->setSound(false);
$push->setBadge(false);
$push->setMessage(false);

ghost avatar Nov 19 '14 22:11 ghost

ok but i think the "alert" key is still exists, empty but exists.. and my iOS developer say that is need to be unset in order for the silent push to work.

did this make any sense?

rhayun avatar Nov 20 '14 05:11 rhayun

What is alert key? You can send silent push (only data for app) if you disable badge, message and sound in push.

ghost avatar Nov 20 '14 10:11 ghost

the payload look like that: $payload['alert'] = '';

the alert key exists also when you:

$push->setSound(false);
$push->setBadge(false);
$push->setMessage(false);

and as i understand its not good when you want a silent push you need not include the 'alert' ket at all

rhayun avatar Nov 20 '14 11:11 rhayun

It's a very old issue but still opened. So to clarify for people reading this, if you want to send a silent push you just need to set an empty string as a message. Although it's not the purpose here, but if you want the same effect with GCM you have a "dry_run" parameter that allows you to send silent pushes if you set it to true.

twysto avatar Nov 14 '16 14:11 twysto

So to clarify for people reading this, if you want to send a silent push you just need to set an empty string as a message.

If you will set badge it would silent push, but also will update badge icon.

ghost avatar Nov 14 '16 15:11 ghost