Andrey Chernukha
Andrey Chernukha

Reputation: 21808

APNS certificates clarification

I was debugging an application that had already been submitted to the App Store. The application uses push notifications. By now i'm done with bugs and i'm going to submit the new version of this app. The problem was that i didn't have distribution certificate so i had to create my own (by requesting a certificate from certificate authority) in order to create AppStore provisioning profile. The question is - will this version of the app support push notifications? Should i sign it with APNS certificate used for previous version or it's not mandatory and i can use my own certificate i have just created?

Upvotes: 1

Views: 789

Answers (2)

Pradeep
Pradeep

Reputation: 1043

  1. Get the csr file from keychan access->Certificate Assistant->Request a certificate From Certificate Authority
  2. submit the csr file while creating the distribution apns certificate
  3. install that cer file and get the p12 file by using export in keychain access
  4. now you have the cer and p12 file, and now you can generate the pem file by using following commands

    a) openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem

    b) openssl pkcs12 -nocerts -out PushChatKey.pem -in Certificates.p12

    c) cat PushChatCert.pem PushChatKey.pem > ck.pem

  5. Now you can send the pem file with your passhrase(i.e generated from above cmds) to your server

  6. php code is also here for testing

    // Put your device token here (without spaces):
    //itouch 4 inch device token for development environment
    $deviceToken = '<device_token_without_spaces>';
    
    // Put your private key's passphrase here:
    $passphrase = '<your pass phrase>';
    
    
    // Put your alert message here:
    $message = 'My first push notification!';
    
    ////////////////////////////////////////////////////////////////////////////////
    
    $ctx = stream_context_create();
    
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
    
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    
    //development
    //$ios_url = 'ssl://gateway.sandbox.push.apple.com:2195';
    
    //production(i.e distribution apns)
    $ios_url = 'ssl://gateway.push.apple.com:2195';
    
    
    // Open a connection to the APNS server
    $fp = stream_socket_client(
        $ios_url, $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    
    if (!$fp)
        exit("Failed to connect: $err $errstr" . PHP_EOL);
    
    echo 'Connected to APNS' . PHP_EOL;
    
    // Create the payload body
    $body['aps'] = array(
        'alert' => $message,
        'sound' => '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)
        echo 'Message not delivered' . PHP_EOL;
    else
        echo 'Message successfully delivered' . PHP_EOL;
    
    // Close the connection to the server
    fclose($fp);
    

Upvotes: 3

Arpit Kulsreshtha
Arpit Kulsreshtha

Reputation: 2162

For this version of app you have to adopt each and every step which you have taken for first version of the application. Follow these steps :-

Create new Certificate Authority , provision profile and SSL and enable the push notification service of this ssl.

Make a .PEM and put it on your server (where Push Notification server files are placed).

Now sign your app with this new profile.

In simple words follow all steps which you have done for version first. Hope this Helps You !

Upvotes: 3

Related Questions