T
T
Timur Kalimullin2017-08-13 19:50:58
PHP
Timur Kalimullin, 2017-08-13 19:50:58

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) ""


There are no errors, but as a result I do not receive notifications on the iphone. What could be the problem?

The application is installed using TestFlight.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Kalimullin, 2017-08-13
@ZetRider

The error was in the certificate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question