Skip to content

Instantly share code, notes, and snippets.

@bartjkdp
Created July 24, 2016 14:18
Show Gist options
  • Save bartjkdp/ad7331f8c23cbe20a7b2bf42323aea6a to your computer and use it in GitHub Desktop.
Save bartjkdp/ad7331f8c23cbe20a7b2bf42323aea6a to your computer and use it in GitHub Desktop.
Send push notification through Apple Push Notification Service (APNS)
<?php
$token = "<device-token>";
$message = array(
'aps' => array(
'alert' => 'hi there',
'badge' => 1,
'sound' => 'default'
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_URL, 'https://api.push.apple.com/3/device/' . $token);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: com.pleio.pleioapp"));
curl_setopt($ch, CURLOPT_SSLCERT, 'apns.crt'); // a file containing with the certificate and the private key concatinated
$response = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment