php - Apple Push notifications working sometimes but not always -
i using php in backend send apple push notification. receiving notifications not.
i know simple code use, if there other ways send notifications. cant understand why not delivering , does.
ps: using production build
function sendpush($user_id,$message,$video_id,$not_type,$devicetoken) { $passphrase = 'xxxxx'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'xxx.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, stream_client_persistent, $ctx); if (!$fp) exit("failed connect: $err $errstr" . php_eol); $body['aps'] = array( 'alert' => $message, 'badge' => '1', 'sound' => 'default'); $body['payload'] = array( 'type' => $not_type, 'user_id' => $user_id, 'video_id' => $video_id ); $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 delivered' . php_eol; fclose($fp); }
keep connections apns open across multiple notifications;
don’t repeatedly open , close connections
. apns treats rapid connection , disconnection denial-of-service attack. should leave connection open unless know idle extended period of time—for example, if send notifications users once day ok use new connection each day.
Comments
Post a Comment