Remote Notification not arriving

Hi I have an issue with Remote notification

I use this PHP code to send notification

function sendNotification($token, $messageText,$sound) {

  $tHost = 'gateway.sandbox.push.apple.com';
  $tPort = 2195;
  // Provide the Certificate and Key Data.
  $tCert = 'cert/pushcert.pem';
  // Provide the Private Key Passphrase (alternatively you can keep this secrete 
  // and enter the key manually on the terminal -> remove relevant line from code).
  // Replace XXXXX with your Passphrase
  $tPassphrase = 'XXXXX';
  // Provide the Device Identifier (Ensure that the Identifier does not have spaces in it).
  // Replace this token with the token of the iOS device that is to receive the notification.
  $tToken = $token;
  // The message that is to appear on the dialog.
  $tAlert = 'You have a LiveCode APNS Message';
  // The Badge Number for the Application Icon (integer >=0).
  $tBadge = 8;
  // Audible Notification Option.
  // The content that is returned by the LiveCode "pushNotificationReceived" message.
  $tPayload = $messageText;
  // Create the message content that is to be sent to the device.
  $tBody['aps'] = array (
    'alert' => $tAlert,
    'badge' => $tBadge,
    'sound' => $sound,
    );
  $tBody ['payload'] = $tPayload;
  // Encode the body to JSON.
  $tBody = json_encode ($tBody);
  // Create the Socket Stream.
  $tContext = stream_context_create ();
  stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
  // Remove this line if you would like to enter the Private Key Passphrase manually.
  stream_context_set_option ($tContext, 'ssl', 'passphrase', $tPassphrase);
  // Open the Connection to the APNS Server.
  $tSocket = stream_socket_client ('ssl://'.$tHost.':'.$tPort, $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
  // Check if we were able to open a socket.
  if (!$tSocket)
    exit ("APNS Connection Failed: $error $errstr" . PHP_EOL);
  // Build the Binary Notification.
  $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);
      }

When I execute this it returns "Delivered Message to APNS" but if I put a breakpoint inside

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
}

no notification arrives. All processes of "registerForPushNotifications" are correct. The strange thing is that everything worked until a month ago. This make me crazy. Please help me

Your issue is due to continued use of the legacy Binary Interface which was retired March 31st, 2021 (https://developer.apple.com/news/?id=c88acm2b).

This change requires you to migrate your push servers to use the HTTP/2 API. Any push servers still using the legacy interface will be unable to connect to APNs, resulting in Push Notifications not working.

More information about the HTTP/2 provider API can be found in these two WWDC sessions:

  • WWDC2015 Whats New in Notifications https://developer.apple.com/videos/play/wwdc2015/720/
  • WWDC2016 Whats New in the Apple Push Notification Service https://developer.apple.com/videos/play/wwdc2016/724/

You can read more about the new APNs Provider API here: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

Add "content-available": 1 to your $tBody['aps']

$tBody['aps'] = array ( 'alert' => $tAlert, 'badge' => $tBadge, 'sound' => $sound, "content-available": 1 );

Remote Notification not arriving
 
 
Q