I phone Push notification

I phone Push notification
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  // device token id..         
 $deviceToken = '1dec4a0c1b5ae0654c6596162b658fbada168d723be43bd9ac2e05e393f21572';
//password generate when key file is generated... generate by iphone developer
            $passphrase = '12345';
// message you want to send in notification.
            $message = 'My first push notification!';
//  "WP_CONTENT_DIR.'/uploads/pushnotification/AAPush.pem" is the path of certificate main .pem file..
            $ctx = stream_context_create();
            stream_context_set_option($ctx, 'ssl', 'local_cert', WP_CONTENT_DIR.'/uploads/pushnotification/AAPush.pem');
            stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

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

            $body['aps'] = array(
                'alert' => $message,
                'sound' => 'default',
                'content-available' => '1'
            );
// use content-aailable for ios backend notificatin handle..
            $payload = json_encode($body);

            $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// in result you got the response.. if no response then you push notification is not working
            $result = fwrite($fp, $msg, strlen($msg));
           
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

No comments:

Post a Comment

Featured post

A23 Rummy - Safe Secure Gaming Platform

A23 Rummy is a popular online rummy platform in India. It is owned and operated by Head Digital Works Private Limited. The platform offers...