Critical Alert Function

I am trying to integrate push notification functionality which will send notifications from PHP script to ios applications. However, push notification is not working in the critical alert. This means, when the ios device is in silent mode, notifications are not coming up. The user gets the pop up to allow the critical alert but then it isn't working.

I have used below code for PHP::

$apnsHost = 'gateway.sandbox.push.apple.com'; $apnsCert = 'pushcert.pem'; $apnsPort = 2195; $apnsPass = '123456'; $token = 'ECE62BE1B57D05CCB0A204F4B03D43267CE70489C150CBA72F249B10DC805417';

$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1, 'sound' => 'default'); $output = json_encode($payload); $token = pack('H*', str_replace(' ', '', $token)); $apnsMessage = chr(0).chr(0).chr(32).$token.chr(0).chr(strlen($output)).$output;

$streamContext = stream_context_create(); stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); stream_context_set_option($streamContext, 'ssl', 'passphrase', $apnsPass);

$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext); if (!$apns) { echo "Error: $errorString ($error)"; } fwrite($apns, $apnsMessage); fclose($apns);

I have done the below steps in IOS: 1> certificate set up 2> created delgate method

Any help appreciated, thanks!

Critical Alert Function
 
 
Q