immobiliare / ApnsPHP

ApnsPHP: Apple Push Notification & Feedback Provider
BSD 3-Clause "New" or "Revised" License
1.44k stars 452 forks source link

Please add an option for silent push #72

Open rhayun opened 9 years ago

rhayun commented 9 years ago
/**
 * 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;
    }
}
ghost commented 9 years ago

already exists

$push->setSound(false);
$push->setBadge(false);
$push->setMessage(false);
rhayun commented 9 years ago

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?

ghost commented 9 years ago

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

rhayun commented 9 years ago

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

twysto commented 7 years ago

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.

ghost commented 7 years ago

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.