Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere should I put .pem files in codeigniter to send Apple push notifications?
    primarykey
    data
    text
    <p>I am developing a Web service in CodeIgniter with a REST_controller library. It is just a controller which manage the requests, I have one request for each method that I use. One of those methods I am trying to use it for send apple Notifications, so I need to use ck.pem file(it is a certificate). I know the problem is that I don't have the good path for the .pem file. </p> <p>This is the code that I am using. I have the ck.pem file in controllers folder and it does not work.</p> <pre><code>function pushtest_get(){ $data = array(); // Put your device token here (without spaces): $deviceToken = 'be67171fb22f3ea8fa68c13a9f2ba7229caf3a487aa656b20f769fa2b1fa5b7a'; // Put your private key's passphrase here: $passphrase = 'miguel'; $message = 'Notification de prueba desde servicio web rest'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL); $data['response'] = 'Connected to APNS' . PHP_EOL; // Create the payload body $body['aps'] = array( 'alert' =&gt; $message, 'sound' =&gt; 'default' ); // Encode the payload as JSON $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) $data['response'] = 'Message not delivered' . PHP_EOL; else $data['response'] = 'Message successfully delivered' . PHP_EOL; // Close the connection to the server fclose($fp); $response-&gt;skills = $data; $this-&gt;response($response, 200); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload