Ciao, con questo codice (premettendo che in locale funziona perfettamente), vorrei inviare delle notifiche push ad alcuni dispositivi iOS:
Codice:
$badge = 1;
$sound = 'default';
$apns_port = 2195;
$payload = array();
$payload['aps'] = array('alert' => $message, 'badge' => intval($badge), 'sound' => $sound);
$payload = json_encode($payload);
if ( Constants::DEVELOPMENT ) {
$apns_url = 'gateway.sandbox.push.apple.com';
$apns_cert = $this->kernel->locateResource(Constants::IOS_CERTIFICATE_SANDBOX);
} else {
$apns_url = 'gateway.push.apple.com';
$apns_cert = $this->kernel->locateResource(Constants::IOS_CERTIFICATE_PRODUCTION);
}
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
$device_tokens = array( $deviceToken );
foreach ($device_tokens as $device_token) {
$apns_message = chr(0).chr(0).chr(32).pack('H*', str_replace(' ', '', $device_token)).chr(0).chr(strlen($payload)).$payload;
fwrite($apns, $apns_message);
}
@socket_close($apns);
@fclose($apns);
Purtroppo ho 500 Internal Server Error,
perche?
grazie