Created
December 30, 2010 07:40
-
-
Save samvermette/759564 to your computer and use it in GitHub Desktop.
Quickly send an Apple Push Notification using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$apnsHost = 'gateway.sandbox.push.apple.com'; | |
$apnsCert = 'apns-dev.pem'; | |
$apnsPort = 2195; | |
$streamContext = stream_context_create(); | |
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); | |
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); | |
$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1, 'sound' => 'default'); | |
$output = json_encode($payload); | |
$token = pack('H*', str_replace(' ', '', $token)) | |
$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output; | |
fwrite($apns, $apnsMessage); | |
socket_close($apns); | |
fclose($apns); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My Server not allow me to open APN Port number, So Finally I've Used Firebase service for that task. It's easy to use and both android, iOS token can easily work now. Let me know if you need any help from my side.
Thanks!
Bhavin