Ios push notification

I am new to php and writing code for push notification in codeigniter, but I got these erros.

Here is my model.

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

Error message:

Message: stream_socket_client (): SSL operation failed with code 1. OpenSSL Error messages: error: 14094410: SSL procedures: SSL3_READ_BYTES: sslv3 message failure message failed Message: stream_socket_client (): Crypto message failed: stream_socket_client (): unable to connect to ssl: //gateway.sandbox.push.apple.com: 2195 (Unknown error)

+4
source share
3 answers

Once you create the provisional certificates and click on the notification for both development and distribution. Follow the steps to create a push notification.

To use the certificates you created, you need to create a PEM file that stores both the Apple Push Notification Service SSL certificate and your private key. You can create a PEM file from the terminal.

Change to the directory containing the certificates and key generated earlier, and follow these steps. The file names here reflect the names of the certificates that were generated as part of this lesson. You must update the syntax to match the names you gave your certificates.

First create a PEM file for the application certificate. You can do this by double-clicking the aps_developer_identity.cer certificate file, then open the Keychain Assistant and export the certificate to the ap12 file, and then convert it to a PEM file in the same way that 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 into a PEM file. Here we select one command line option, as shown below:

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

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

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

Enter the password to import: MAC is confirmed OK Enter the phrase: Verify - enter the phrase to send PEM:

Now merge the two files:

 cat PushNotificationAppCertificate.pem PushNotificationAppKey.pem > PushNotificationAppCertificateKey.pem 

Open a Mac terminal and run the following line from the directory containing the certificates you created:

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

Then you are prompted to enter the password for the passed key:

 Enter pass phrase for PushNotificationAppKey.pem: 

If everything worked, the server should send you a lot of information, which might look something like this:

 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 connection to the server and checks if our certificates are working.

enter image description here

+5
source

I had the same problem as you mentioned here. It took a while and a head to find ...

The solution I discovered that I fixed the handshake error was to download the entrust certificate and include it in the stream context using the code below:

 $entrustCert = '<full path to cert>/entrust_2048_ca.cer'; stream_context_set_option($ctx, 'ssl', 'cafile', entrustCert); 


There seems to be intermittent connectivity issues using the APN service for the sandbox. Sometimes I get errors, for example:

 Warning: stream_socket_client(): SSL: Connection reset by peer Warning: stream_socket_client(): Failed to enable crypto 


Hope it will be time for someone!

+1
source
 function send_iOS_notifications($device_tokens, $notification_content) { $this->load->library('apn'); $this->apn->payloadMethod = 'enhance'; // you can turn on this method for debuggin purpose $this->apn->connectToPush(); //$badge_count = $this->set_and_get_ios_active_notifications('',$device_token); // adding custom variables to the notification $this->apn->setData($notification_content); $message = $notification_content['message']; if ((strpos($message, 'http://') !== false) || (strpos($message, 'https://') !== false)) { $message = "Image"; } //$send_result = $this->apn->sendMessage($device_token, 'Test notif #1 (TIME:'.date('H:i:s').')', /*badge*/ 2, /*sound*/ 'default' ); $send_result = $this->apn->sendMessage($device_tokens, $message, /*badge*/ '', /*sound*/ 'default' ); if($send_result){ log_message('debug','Sending successful'); $result['status'] = true; $result['message'] = 'Sending successful'; } else{ log_message('error',$this->apn->error); $result['status'] = true; $result['message'] = $this->apn->error; } $this->apn->disconnectPush(); } 
0
source

All Articles