title: iOs 10 - SWIFT 3 - Notification push
body: <p>I have a little problem with notification push and iOs 10 (with Swift 3)..</p>
  
  <p>I followed this tutorial : <a href="https://www.sitepoint.com/developing-push-notifications-for-ios-10/" rel="nofollow noreferrer">https://www.sitepoint.com/developing-push-notifications-for-ios-10/</a>
  With <strong>Pusher</strong>, it's ok, works fine..
  I receive the notification on my phone.</p>
  
  <p>But I would like to send notifications from my web server..
  I generate my .pem file (<a href="http://www.apptuitions.com/generate-pem-file-for-push-notification/" rel="nofollow noreferrer">http://www.apptuitions.com/generate-pem-file-for-push-notification/</a>)</p>
  
  <p>My php code :</p>
  
  <pre><code>$apnsServer = 'ssl://gateway.sandbox.push.apple.com:2195';
  $privateKeyPassword = 'mykey';
  $message = "My message here !";
  $deviceToken ='MYTOKENHERE';
  
  $pushCertAndKeyPemFile = 'pushcert.pem';
  $stream = stream_context_create();
  stream_context_set_option($stream,'ssl','passphrase',$privateKeyPassword);
  stream_context_set_option($stream,'ssl','local_cert',$pushCertAndKeyPemFile);
  $connectionTimeout = 30;
  $connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
  $connection = stream_socket_client($apnsServer, $errorNumber, $errorString, $connectionTimeout,$connectionType,$stream);
  
  if (!$connection){
      echo "Failed to connect to the APNS server. Error = $errorString &lt;br/&gt;";
      exit;
  }
  else{
      echo "Successfully connected to the APNS. Processing...&lt;/br&gt;";
  }
  $messageBody['aps'] = array('alert' =&gt; $message,'badge' =&gt; 1, 'sound' =&gt; 'default');
  $payload = json_encode($messageBody);
  $notification = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
  $wroteSuccessfully = fwrite($connection, $notification, strlen($notification));
  
  if (!$wroteSuccessfully){
      echo "Could not send the message&lt;br/&gt;";
  } else {
      echo "Successfully sent the message&lt;br/&gt;";
  }
  </code></pre>
  
  <p>Result : 
  <strong>Successfully connected to the APNS. Processing...</strong>
  <strong>Successfully sent the message</strong> 
  But I never receive notification on my phone</p>
  
  <p>Why ?
  How to send a notification push with php ?</p>
  
  <p>Thanks for your help :)</p>
  
  <p><strong>[EDIT]
  Ok, i found a solution..
  Just add at the end:</strong></p>
  
  <pre><code>fclose($connection);
  </code></pre>