Search code examples
phpapns-php

using pem with password for apns - php


Apologies if this is a basic but cant seem to find exact solution anywhere.

have a php code for APNS set up and working normally. have now been given the production pem file which is password protected.

kindly instruct where/how to pass that password parameter in the php. the push code is as follows:

 $apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = GetPemUrl();

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);

$sent = False;

if ($apns) {
    $apm = fwrite($apns, $apnsMessage);

    if ($apm)
    {
        $sent = true;
    }
    else
    {
        $sent = FALSE;
    }

    //socket_close($apns);
    fclose($apns);
}

Solution

  • co-incidentally found the solution and am posting in case someone else may need it. add another option to stream context like so:

    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
    stream_context_set_option($streamContext, 'ssl', 'passphrase', "pem file passphrase"); // simlply add this
    

    following is the link for complete post:

    http://learn-php-by-example.blogspot.com/2013/01/working-with-apple-push-notification.html