Reputation: 49
i have a problem with Notifications in ios13. If i use gateway.sandbox i can see the notification, but i'have downloaded the app directly from AppStore. Instead using gateway.apple i see 'Delivered Message to APNS', but nothing on my device. I also tried to recreate the Certificate, .p12 and .pem file.
Any idea? Thank you
This is my php
public function iOS($data, $devicetoken)
{
// $tHost = 'gateway.sandbox.push.apple.com';
$tHost = 'gateway.push.apple.com';
$tPort = 2195;
$tCert = 'pushcert.pem';
$tPassphrase = 'pushcertpsw12';
$tToken = $devicetoken;
$tSound = 'default';
$tPayload = 'APNS payload';
$tBody['aps'] = array(
'apns-priority' => 10,
'badge' => +1,
'alert' => $data['mtitle'] .' ' .$data['mdesc'],
'sound' => 'default'
);
$tBody ['payload'] = $tPayload;
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
$tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
if (!$tSocket)
exit ('APNS Connection Failed:' .$error. ' ' .$errstr . PHP_EOL);
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;
// Send the Notification to the Server.
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult)
echo 'Delivered Message to APNS' . PHP_EOL;
else
echo 'Could not Deliver Message to APNS' . PHP_EOL;
// Close the Connection to the Server.
fclose ($tSocket);
Upvotes: 0
Views: 284
Reputation: 453
There are two different environments of APNS tokens; Sandbox and Production. They require completely separate setups, permissions, registration, and push setups. Pushing a Sandbox APNS notification to a Production token will not work, the same with Production APNS to Sandbox token.
If you have verified in Sandbox but not in production, you probably need to dupe all your permissions and certificates for production. Also double check where you're pushing to with your PHP code and ensure it's the correct environment (Sandbox vs Prod).
Upvotes: 1