iphone - Apple Push Notification Service with PHP Script -
i'm trying send push notifications ton iphone (apns). read post , try implement it. certificates (normaly).
now have php script :
$device = '4f30e047 c8c05db9 3fa87e7d ca5325f7 738cb2c0 0b4a02d4 d4329a42 a7128173'; // iphone devicetoken $payload['aps'] = array('alert' => 'this alert text', 'badge' => 1, 'sound' => 'default'); $payload['server'] = array('serverid' => $serverid, 'name' => $name); $output = 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);
when run script nothing happen. no error empty page iphone doesn't receive push notification ...
have got idea?
thanks lot !
no space in device token, strip them
Comments
Post a Comment