在ios中推送通知 [英] push notification in ios

查看:157
本文介绍了在ios中推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的PHP,并在codeigniter中编写推送通知的代码,但我得到了这些错误。

I am new in a php and write a code for push notification in codeigniter but I got these erros.

这是我的模特..

function sendmessage($appid, $deviceid, $status, $message)
{

    $deviceToken = '0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78';

    $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', 'essar@123');

    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

    if (!$fp){
        exit("Failed to connect: $err $errstr" . PHP_EOL);
              }
          else {
          print "Connection OK/n";
               }
    echo 'Connected to APNS' . PHP_EOL;

    $body['aps'] = array(
        'alert' => $message,
        'sound' => 'default'
        );
    $payload = json_encode($body);
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result)
        echo 'Message not delivered' . PHP_EOL;
    else
        echo 'Message successfully delivered' . PHP_EOL;
    fclose($fp);

    $data = array(
    'message' => $this->message . 'add',
    'appid' => $this->appid,
    'deviceid' => $this->deviceid,
    'status' => $status
            );
    $this->sendmessage($data);

错误信息:


消息:stream_socket_client():SSL操作失败,代码为1. OpenSSL错误消息:错误:14094410:SSL例程:SSL3_READ_BYTES:sslv3警报握手失败消息:stream_socket_client():无法启用加密消息:stream_socket_client():无法连接到ssl://gateway.sandbox.push.apple.com:2195(未知错误)

Message: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure Message: stream_socket_client(): Failed to enable crypto Message: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)


推荐答案

为开发和分发创建临时证书和推送通知。按照生成推送通知

Once you created the provisional certificates and push notification for both development and distribution. Follow the steps for Generate Push Notification

要使用您生成的证书,您需要创建 PEM文件存储Apple推送通知服务SSL证书和私钥。您可以从终端创建PEM文件。

In order to use the certificates you generated, you need to create a PEM file that stores both, your Apple Push Notification Service SSL Certificate and your Private Key. You can create the PEM file from a terminal.

导航到包含先前生成的证书和密钥的目录,然后执行以下步骤。此处的文件名反映了作为本课程一部分生成的证书的名称。您必须根据您提供证书的名称更新语法。

Navigate to the directory that contains the certificates and key you generated earlier and execute the following steps. The file names here reflect the names of the certificates that were generated as part of this lesson. You have to update the syntax according the names you gave your certificates.

首先创建应用程序证书PEM文件。您可以通过双击aps_developer_identity.cer证书文件,然后打开Keychain Assistant并将证书导出为ap12文件,然后将其转换为PEM文件,方式与PushNotificationApp.p12转换为PEM相同。文件。或者,您可以使用单个命令行将aps_developer_identity.cer证书文件直接转换为PEM文件。这里我们选择单命令行选项,如下所示:

First create the application certificate PEM file. You can do this by double clicking on the aps_developer_identity.cer certificate file, then opening the Keychain Assistant and exporting the certificate as ap12 file and then converting it to a PEM file, in the same fashion as the PushNotificationApp.p12 is converted to a PEM file. Alternatively you can use a single command line that converts the aps_developer_identity.cer certificate file directly to a PEM file. Here we are opting for the single command line option, as follows:

openssl x509 -inform der -outform pem -in aps_developer_identity.cer -out PushNotificationAppCertificate.pem

现在创建应用程序密钥PEM文件,如下所示。您需要输入导入密码和PEM密码短语:

Now create the application key PEM file as follows. You need to enter the import password and PEM pass phrase:

openssl pkcs12 -in PushNotificationApp.p12 -out PushNotificationAppKey.pem -nocerts

输入导入密码:
MAC已验证确定
输入PEM密码短语:
验证 - 输入PEM密码短语:

Enter Import Password: MAC verified OK Enter PEM pass phrase: Verifying - Enter PEM pass phrase:

现在连接两个文件:

cat PushNotificationAppCertificate.pem PushNotificationAppKey.pem > PushNotificationAppCertificateKey.pem

打开Mac终端并从包含您生成的证书的目录中执行以下行:

Open a Mac terminal and execute the following line from the directory that contains the certificates you generated:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushNotificationAppCertificate.pem -key PushNotificationAppKey.pem

然后,系统会要求您输入您提交的密钥的密码短语:

You are then asked to enter the pass phrase for the key you submitted:

Enter pass phrase for PushNotificationAppKey.pem:

如果一切正常,那么服务器应该向您发送大量可能如下所示的信息:

If everything worked, then the server should send you a lot of information that may look something like the following:

CONNECTED(00000003)

depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate verify return:0
...
Key-Arg : None

Start Time: 1326899631 Timeout : 300 (sec) Verify return code: 0 (ok)
At the end of this, you can enter some text and then select the return key. We entered the text "**Hello World**".

**Hello World

closed**

这样就完成了与服务器的通信,并验证我们的证书是否有效。

This completes the communication with the server and verifies that our certificates work.

这篇关于在ios中推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆