Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:17:20+00:00 2026-05-27T22:17:20+00:00

I have generated the .cer file, provision file with the correct device ID, generated

  • 0

I have generated the .cer file, provision file with the correct device ID, generated the .pem file by combining the .cer and private key files, uploaded it to the server. The app id matches. I have provided the passphrase too, which is correct.

I tested the port and connection using telnet from the server, it connects fine.

I have tested the certificate by openssl command, and it returned 0 – no errors.

The certificates and the application is in development/debug mode, the iPhone is set up to receive notifications, the token is received and is delivered to the server correctly and in the same length – 64.

When sending the message from the server, the error code is 0 – which means no errors.

Here is the code sample from the server:

$options = array('ssl' => array(
  'local_cert' => 'cert.pem',
  'passphrase' => 'pass'
));

$streamContext = stream_context_create();
stream_context_set_option($streamContext, $options);
$apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);

if ($apns)
{
    $payload['aps'] = array('alert' => 'push test', 'badge' => 1, 'sound' => 'default');
    $payload = json_encode($payload);

    $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
    fwrite($apns, $apnsMessage);

    fclose($apns);
} 
else 
{ 
    echo "Connection failed";
    echo $errorString."<br />";
    echo $error."<br />";
}

What else can I possibly try?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:17:20+00:00Added an answer on May 27, 2026 at 10:17 pm

    The code that worked in the end is the following:

        $ctx = stream_context_create();
    
        stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem');
        stream_context_set_option($ctx, 'ssl', 'passphrase', 'pass');
    
        // Create the payload body
        $body['aps'] = array(
        'alert' => array('body' => 'Message', 'action-loc-key' => 'Show'),
        'sound' => 'default'
        );
    
        // Encode the payload as JSON
        $payload = json_encode($body);
    
        // Open a connection to the APNS server
        $apns = stream_socket_client(
        'ssl://gateway.sandbox.push.apple.com:2195', $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    
        if (!$apns)
        {
            echo "Failed to connect: $err $errstr" . PHP_EOL;   
        }
    
        echo 'Connected to APNS' . PHP_EOL;
    
        $imsg = chr(0) . pack('n', 32) . pack('H*', $message) . pack('n', strlen($payload)) . $payload;
    
                // Send it to the server
        $res = fwrite($apns, $imsg, strlen($imsg));
    
        if (!$res)
        {
            echo 'Message not delivered' . PHP_EOL;
        }
        else
        {
            echo 'Message successfully delivered' . PHP_EOL;
        }
        fclose($apns);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a developer license and I've generated .mobileprovision and .cer files. I've put
I have generated a public key, private key pair. I've set the public key
I have generated using openssl mycert.pem which contents the certificate. And I converted the
I have generated a bunch of png files to use as markers on my
I have a generated txt file. This file has certain lines that are superfluous,
I have generated a proxy class from a wsdl file (C# VS 2008) The
I have generated excel file. When I try open it, I get error Problems
I have generated a LinqtoSQL mapping xml file, which I have a valid XSD
I have generated a Google map key by login as a user1@gmail.com . Is
I have generated some scaffolding for my rails app. I am running the generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.