php - Using push notification using Api -


i trying use push notification using api , not getting error message neither getting response.

i have checked apple push notification service php script

and applied changes in code accordingly still not working.

i not able how serverid have use in

$device = 'fbb5a9c71066794d57fee33b4005a89f1bb8941a68660fd6e91f466be1299ab6'; // iphone devicetoken $payload['aps'] = array(     'alert' => 'this alert text',     'badge' => 1,     'sound' => 'default' );  $payload['server'] = array(     'serverid' => 1,     'name' => 'keyss.in' );  $payload = json_encode($payload);  $apnscert = 'apple_push_notification_production.pem';  $streamcontext = stream_context_create(); stream_context_set_option($streamcontext, 'ssl', 'local_cert', $apnscert);  $apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $error, $errorstring, 2, stream_client_connect, $streamcontext);  $apnsmessage = chr(0) . chr(0) . chr(32) . pack('h*', str_replace(' ', '', $device)) . chr(0) . chr(strlen($payload)) . $payload; fwrite($apns, $apnsmessage);  //socket_close($apns); seems wrong here ... fclose($apns); 

getting errors:

warning: stream_socket_client(): unable connect ssl://gateway.sandbox.push.apple.com:2195 (connection timed out)

warning: fwrite() expects parameter 1 resource, boolean given

warning: fclose() expects parameter 1 resource, boolean given

you not getting response because using old binary notification format :

$apnsmessage = chr(0) . chr(0) . chr(32) . pack('h*', str_replace(' ', '', $device)) . chr(0) . chr(strlen($payload)) . $payload; 

in order responses (responses returned in case of error), use enhanced format :

$apnsmessage = pack("c", 1) . pack("n", $apple_identifier) . pack("n", $apple_expiry) . pack("n", 32) . pack('h*', str_replace(' ', '', $devicetoken)) . pack("n", strlen($payload)) . $payload; 

you can see sample code here.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -