【问题标题】:APNS certificates clarificationAPNS 证书说明
【发布时间】:2013-08-26 11:45:50
【问题描述】:

我正在调试一个已经提交到 App Store 的应用程序。该应用程序使用推送通知。到目前为止,我已经完成了错误,我将提交这个应用程序的新版本。问题是我没有分发证书,所以我必须创建自己的(通过从证书颁发机构请求证书)才能创建 AppStore 配置文件。问题是——这个版本的应用程序是否支持推送通知?我应该使用以前版本的 APNS 证书对其进行签名,还是不是强制性的,我可以使用我刚刚创建的自己的证书?

【问题讨论】:

  • 继续,我不认为你更新的代码会影响推送通知,除非你有 pem 文件到你的服务器
  • 我没有 pem 文件
  • @AndreyChernukha 如果您没有 .pem 文件,请创建它。并将其放置在您的服务器文件所在的位置。

标签: ios ssl-certificate apple-push-notifications


【解决方案1】:

对于这个版本的应用程序,您必须采用您为应用程序的第一个版本所采取的每一个步骤。请按照以下步骤操作:-

新建Certificate Authority、provision profile和SSL,并启用该ssl的推送通知服务。

创建一个.PEM 并将其放在您的服务器上(其中放置了Push Notification 服务器文件)。

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

简单地说,首先按照您为版本完成的所有步骤操作。希望这对您有所帮助!

【讨论】:

  • 嘿,伙计,您的回答似乎不正确。当我开始在开发者帐户中创建新的 APNS 证书时,有两个选项可用:APNS 证书和 AppStore 证书。所以它们是两个不同的东西,这意味着我必须使用 AppStore 证书来创建配置文件。
  • 嘿伙计,没有像 APNS 证书这样的术语。您必须选择它来分发 SSL 证书,以便在应用商店上传应用。
  • 在进一步处理之前请阅读raywenderlich.com/32960/…
  • 你能给我解释一件事吗?当我为推送通知创建证书时-仅服务器端需要它,是吗?我不会在其他任何地方使用它,对吧?
  • 而且似乎我不必第二次设置推送通知。看看这个问题:stackoverflow.com/questions/18268024/…
【解决方案2】:
  1. 从 keychan 访问获取 csr 文件->证书助手->从证书颁发机构请求证书
  2. 在创建分发 apns 证书时提交 csr 文件
  3. 安装该 cer 文件并通过在钥匙串访问中使用 export 获取 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) 猫 PushChatCert.pem PushChatKey.pem > ck.pem

  5. 现在您可以将带有密码的 pem 文件(即从上面的 cmds 生成)发送到您的服务器

  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);
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多