Push Notifications Console: Apple’s Game-Changing New Tool

Discover the new Push Notifications Console Apple released at WWDC 2023, designed to simplify sending notifications for testing. Say goodbye to custom scripts and unreliable third-party applications: This console revolutionizes your push notification testing process. By Scott Grosch.

Leave a rating/review
Save for later
Share

At WWDC ’23, Apple announced the Push Notifications Console, a much-needed new tool to simplify creating and testing your push notifications.

For years, developers have struggled with push notifications. Each developer had to write custom scripts to not only generate the appropriate payload, but also handle the authentication to APNs. In later years, Apple simplified the process by allowing the simulator to trigger a notification by dropping in a JSON payload.

Thanks to the Push Notifications Console, you can now say goodbye to those clunky, outdated methods. But first, you’ll take a look at how push notifications have worked so far.

Note: If you need to brush up on your push notification skills, check out our book: Push Notifications by Tutorials. It covers everything you need to know about rich media notifications, notification actions, grouped notifications and more.

Sending Push Notifications — the Old Way

Until now, when you needed push notifications, you’ve probably written a script with code like this:

function generateAuthenticationHeader()
{
  $header = base64_encode(json_encode(['alg' => 'ES256', 'kid' => AUTH_KEY_ID]));
  $claims = base64_encode(json_encode(['iss' => TEAM_ID, 'iat' => time()]));

  $pkey = openssl_pkey_get_private('file://' . AUTH_KEY_PATH);
  openssl_sign("$header.$claims", $signature, $pkey, 'sha256');

  $signed = base64_encode($signature);

  return "$header.$claims.$signed";
}

function sendNotifications($token, $debug) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($GLOBALS['payload']));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'apns-topic: ' . BUNDLE_ID,
      'authorization: bearer ' . generateAuthenticationHeader(),
      'apns-push-type: alert'
  ]);

  $server = $debug ? 'api.development' : 'api';
  $url = "https://$server.push.apple.com/3/device/$token";
  curl_setopt($ch, CURLOPT_URL, "{$url}");

  $response = curl_exec($ch);
  if ($response === false) {
    echo("curl_exec failed: " . curl_error($ch));
    continue;
  }

  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  if ($code === 400 || $code === 410) {
    $json = @json_decode($response);
    if ($json->reason === 'BadDeviceToken') {
        // Do something here.
    }
  }

  curl_close($ch);
}

While that works, it isn’t pretty.

Various apps from the Mac App Store also promise to make push notifications easier, but they frequently don’t keep up with changes to the APN’s packet format and headers you may wish to use.

Now, you’ll take a look at the Push Notifications Console and how it improves push notification testing.

The New Push Notifications Console

To try Apple’s new tool, point Safari to the CloudKit Console and click the new Push Notifications item:

bordered

If your app isn’t configured to receive push notifications, you’ll have the option to enable them:

bordered

If you have more than one app configured in the developer portal, select the appropriate one from the drop-down at the top-left of the page.

Clicking Create New Notification will present you with a screen allowing you to easily configure the notification you wish to send:

bordered

The new console makes it simple to provide all the required configuration settings. It also clearly shows the four items that must be sent as HTTP headers, as opposed to part of the payload.

Configuring the Payload

Apple provides a nice set of defaults for the payload configuration, enabling you to enter simple messages rapidly. If you have already prepared a custom JSON payload, you can just toggle the JSON View switch, then paste in your payload directly:

bordered

Not only does the console validate that you’ve provided proper JSON, but it also notifies you if the payload doesn’t seem to conform to the apns-push-type you selected.

You can toggle the JSON View on and off to switch between formats. A good strategy is to use the default view to enter most of the data, then switch to the JSON view when entering an array of items to reduce the amount of mouse-clicking you need to do.

Debugging With the Delivery Log

Another great feature now available to developers is the delivery log. After sending your notification, this feature will immediately present you with a page showing the details of the sent notification as well as the log:

bordered

The logs will help you identify not only whether or not the push notification was successful, but also why it wasn’t delivered on failure.

Never before have developers had such a simple method of debugging push notification issues!

Where to Go From Here?

This was just a brief overview of new push notification features. To learn more:

We hope you enjoyed this quick look at what’s new in push notifications. If you have any questions or comments, please click the Comments link to join the forum discussion below!