I\'m trying so send push notifications ton my iPhone (APNS). I read this post and try to implement it. So all my certificates are good (normaly).
Now I have this php
To send notifications success fully you have to do 1 more thing.
Replace $output = json_encode($payload);
to $payload = json_encode($payload);
If you have more than one device and you loop through them I found that you have to create a new stream_context_create for each fwrite to prevent apple from closing the connection for a bad token.
FYI
You are missing to provice certificate private key. Add this row: stream_context_set_option($streamContext, 'ssl', 'passphrase', $certificatePrivateKey);
For development certificate you need url
'ssl://gateway.sandbox.push.apple.com:2195'but for production
'ssl://gateway.push.apple.com:2195'
no space in device token, strip them
Strip the spaces from token and even then it's not work then
$apnsHost = 'gateway.sandbox.push.apple.com';
Remove "sandbox" from this url and it will run.