IOS Remote Notification

Source: Internet
Author: User

1. Local Certificate synthesis

RM *. Pemecho"Export cert ..."OpenSSL pkcs12-clcerts-nokeys- outPUSH_CERT.PEM-inchPush_cert.p12echo"Export Key ..."OpenSSL pkcs12-nocerts- outPUSH_KEY.PEM-inchpush_key.p12openssl RSA-inchPUSH_KEY.PEM- outPush_key_noenc.pemecho"Combine together"Cat Push_cert.pem Push_key_noenc.pem> apns-Dev.pemecho" Done"

Among them, PUSH_CERT.P12 and PUSH_KEY.P12 are the certificates and private keys which are based on the development certificate in keychain.

The above script will eventually export an authentication file called "Apns-dev.pem".

The following will use this authentication file for Sanbox push

2. Sandbox push

<?PHP$deviceToken=86441e1421a239d0f7eed26ab4c8bd9a9ccec21b‘; $body=Array("APS" =Array("Alert" = ' message ', "badge" = 2, "sound" = ' default ')); $ctx=stream_context_create();stream_context_set_option($ctx, "SSL", "Local_cert", "Apns-dev.pem");$Pass = "AABB11";stream_context_set_option($ctx, ' SSL ', ' passphrase ',$pass);//$fp = stream_socket_client ("ssl://gateway.push.apple.com:2195", $err, $errstr, A, stream_client_connect, $ctx); For real push service$fp=stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195",$err,$errstr, Stream_client_connect,$ctx);//For Sandboxif(!$fp) {    Echo"Failed to connect$err $errstrn"; return;}Print"Connection ok\n";$payload= Json_encode ($body);$msg=CHR(0).Pack("n", 32).Pack("h*",Str_replace(‘ ‘, ‘‘,$deviceToken)) .Pack("N",strlen($payload)) .$payload;Echo"Sending message:".$payload." \ n ";fwrite($fp,$msg); fclose($fp);?>

One of the Devicetoken is the 40-bit udid of the Apple phone.

This was learned at the time of the internship, but in the end the program was not tested successfully:

The problem is:

PHP pushtest.php

Warning:stream_socket_client (): Failed to enable crypto in pushtest.php on line 10

Warning:stream_socket_client (): Unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in pushtest.php on line 10

I really regret to hope that I will have the opportunity to learn about iOS!

IOS Remote Notification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.