SoFunction
Updated on 2025-04-03

Detailed explanation of the generated and pushed pem files in IOS development

Detailed explanation of the generated and pushed pem files in IOS development

The specific steps are as follows:

First of all, a pem certificate is required, which needs to be consistent with the signature used during development. The specific method of generating pem certificates is as follows:

1. Log in to the iPhone Developer Connection Portal (/iphone/manage/overview/) and click App IDs

2. Create an App ID that does not use wildcards. Wildcard ID cannot be used for push notification services. For example,

3. Click "Configure" next to the App ID, and then press the button to produce a push notification license. Follow the steps of the "wizard" to generate a signature and upload it, and finally download the generated license.

4. Introduce your aps_developer_identity.cer into Keychain by double-clicking the .cer file.

5. Start the Keychain Assistant on your Mac, and then select the Certificates category in the login keychain. You will see an extensible option "Apple Development Push Services"

6. Expand this option and right-click "Apple Development Push Services" > Export "Apple Development Push Services ID123". Save as apns-dev-cert.p12 file.

7. Extend "Apple Development Push Services" Do the same for "Private Key" and save it as apns-dev-key.p12 file.

8. You need to convert these files to PEM format through terminal commands:

openssl pkcs12 -clcerts -nokeys -out  -in apns-dev-cert.p12
openssl pkcs12 -nocerts -out  -in apns-dev-key.p12

9. If you want to remove the password, either do not set or execute when exporting/converting:

openssl rsa -in  -out 

10. Finally, you need to synthesize the key and license files into files, which you need to use when connecting to APNS:

cat   > 

Implementation code:

<?php      
$_POST['token'] = "fe28006a9d57b0727514cf42e9549446f0d4fc509cdexxxxxxxxxx"; 
    $deviceToken = $_POST['token']; //Get the token of the device, see the following article    $body = array("aps" => array("alert" => "message123gggg32323333", "badge" => 1, "sound"=>'default')); //Push method, including prompt content, prompt method and prompt sound.     
    $ctx = stream_context_create(); 
     
    //If you look for pem path on a Windows server, you will have problems, and modify the path to this method:    $pem = !empty($this->cfg['isga']) && $this->cfg['isga'] == 2?'':''; // All temporary development status    stream_context_set_option($ctx, 'ssl', 'local_cert', "/data/web/cert/".$pem); 
    //Linux server can directly write the path of pem     
    stream_context_set_option($ctx, 'ssl', 'local_cert', <pre name="code" class="html">"/data/web/cert/".$pem); 
<pre name="code" class="html"><pre name="code" class="html">    //If your pem has a password, you need to add a password to log in statementstream_context_set_option($ctx, 'ssl', 'passphrase', ''); 
     
    //If your pem has a password, you need to add a password to log in statement    //$pass = ”123123“; 
    //stream_context_set_option($ctx, ‘ssl', ‘passphrase', $pass); 
     
    //There are two servers to choose here. If it is for development and testing, select the second sandbox server and use the Dev pem certificate. If it is released, use the Product pem and select the official server.    $fp = stream_socket_client("ssl://:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 
     
    $fp = stream_socket_client("ssl://:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 
     
    if (!$fp) {     
      print_r("Failed to connect $err $errstrn");     
      return;     
    }     
    print_r("Connection OK\n");     
    $payload = json_encode($body);     
    $msg = chr(0).pack("n", 32).pack('H*', str_replace(' ', '', $deviceToken)).pack("n",strlen($payload)).$payload;         
    print_r("sending message :".$payload."\n");     
    fwrite($fp, $msg);     
    fclose($fp); 


The above is a detailed explanation of the examples of the pushed pem files generated and pushed in IOS development. If you have any questions, please leave a message or go to the community of this site to communicate and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!