Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent Push Notification #30

Closed
azhararmar opened this issue Dec 1, 2017 · 2 comments
Closed

Silent Push Notification #30

azhararmar opened this issue Dec 1, 2017 · 2 comments

Comments

@azhararmar
Copy link

azhararmar commented Dec 1, 2017

Hi,

I need to send silent push notification, for which I am using the following code

$authProvider = AuthProvider\Token::create($this->options['ios']);
$alert = Alert::create()->setTitle($this->title);
$alert = $alert->setBody($this->message);
$payload = Payload::create()->setAlert($alert);
$payload->setContentAvailability(true);
$payload = $payload->setSound('default');
foreach ($this->data as $key => $value) {
    $payload = $payload->setCustomValue($key, $value);
}
$notifications = [];
foreach ($this->deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload, $deviceToken);
}
$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);
$client->push();

It sends the push notification to the device, however, the push notifications are displayed in notification center which I don't want.

How to include content-available=1 to enable and send silent push notification using this library.

@zloadmin
Copy link

I think you did it

$payload->setContentAvailability(true);

@koenhoeijmakers
Copy link

Do NOT set the apn alert object (things like title, body etc), if you leave those out your push is going to be silent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants