1

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?

4

2 回答 2

3

对于此版本的应用程序,您必须采用您为应用程序的第一个版本所采取的每一个步骤。按着这些次序 :-

创建新Certificate Authority的,提供配置文件并SSL启用此 ssl 的推送通知服务。

制作一个.PEM并将其放在您的服务器上(放置Push Notification服务器文件的位置)。

现在使用这个新配置文件为您的应用程序签名。

简而言之,请遵循您首先为版本所做的所有步骤。希望这对您有所帮助!

于 2013-08-26T11:55:49.890 回答
3
  1. 从keychan access->Certificate Assistant->Request a certificate From Certificate Authority获取csr文件
  2. 在创建分发 apns 证书时提交 csr 文件
  3. 通过在钥匙串访问中使用导出来安装该 cer 文件并获取 p12 文件
  4. 现在您有了 cer 和 p12 文件,现在您可以使用以下命令生成 pem 文件

    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. 现在您可以使用您的密码(即从上面的 cmds 生成)将 pem 文件发送到您的服务器

  6. php代码也在这里用于测试

    // 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);
    
于 2013-08-26T12:12:30.563 回答