Answer the question
In order to leave comments, you need to log in
Why can't I receive push notifications on ios (php apns)?
Good afternoon,
from the ios developer I received a .pem certificate and a token of my device for sending push notifications from the server.
Send notification in the following way:
<?
$token = 'ххх';
$message = 'Hello';
$badge = 1;
$sound = 'default';
$cert = __DIR__ . '/cert.pem';
$payload = json_encode(array(
'aps' => array(
'alert' => $message,
'badge' => (int) $badge,
'sound' => $sound
)
));
$apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $cert);
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $error_string, 2, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $stream_context);
$result = fwrite($apns, $apns_message, strlen($apns_message));
@socket_close($apns);
@fclose($apns);
echo '<pre>Result:<br>';
var_dump($result); // int(90)
echo '<br>Error:<br>';
var_dump($error); // int(0)
echo '<br>Error String:<br>';
var_dump($error_string); // string(0) ""
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question