Testing Apple Remote Push Notifications with Request Headers and Payloads

Sarath Sasikala
3 min readOct 10, 2023

During WWDC23, Apple introduced a Push Notification Console for sending test notifications and monitoring their delivery status.

Utilize the Apple Push Notification Console to:

  • Send remote notifications
  • Access delivery logs
  • Monitor notification status
  • Debug and authenticate tokens

Requirement:

  • Apple Developer account.

Access the Apple Push Notification Console

Sign in using your Apple Developer Program account and visit: https://icloud.developer.apple.com/dashboard/notification

Create and send a test push notification

The Push Notification Console provides guidance on configuring various push notification parameters and retains a 30-day history of dispatched notifications.

Create new Notification

Environment: Two environment options are available Development and Production. Production environment notifications are accessible only with admin privileges. Xcode assigns APS Environment Entitlement values based on your app’s provisioning profile. For example, using a development profile sets it to Development, while production profiles and prerelease versions default to Production.

Device Token: Get the device token from the AppDelegate in the didRegisterForRemoteNotificationsWithDeviceToken delegate method.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
print(token)
}

The device token should be a minimum of 64 characters long and in hexadecimal format. Starting from Xcode 14, the simulator also supports remote push notifications, and it returns a push token with more than 64 characters.

Sample Device tocken:
Device (64 Characters): b3f50367d23f83183cf9c0835756c0d94d93362284cefa21410bb1a58de00b9b
Simulator (160 Characters): 800bdd8dbf314d401898d0e5193481285824eefe0feb1e434004a71b2591593fefd654938f5649f30945c60d32cb99e19295a9906f168757b8190ca36386f99500eb7b5e4e8030a0e8f61e76718b76ec

Request Headers:

apns-push-type: This header field has the following valid options.

  • alert: User-interactive notifications.
  • background: Content delivery in the background.
  • location: Location-related notifications.
  • voip: Voice-over-IP call notifications.
  • complication: Watch app complications updates.
  • fileprovider: File Provider extension changes.
  • mdm: Managed device instructions.
  • liveactivity: Live activity session updates.
  • pushtotalk: Push-to-talk service updates.

apns-expiration: Defines notification validity period.

  • Attempt delivery once: APNs delivery attempt without storage, may involve retries.
  • Specify expiration date: APNs store the notification and make repeated delivery attempts until the specified date.

apns-priority: The priority of the notification.

  • Low(1): Prioritize device power over all other factors and prevent device awakening during delivery.
  • Medium(5): Balance delivery with device power considerations.
  • High(10): Immediate notification delivery.

Payload:

Create a new Notification Payload
Create a new Notification Payload JSON View

Utilize the payload editor to enter raw JSON or construct the payload via the interface. The editor’s layout adapts to the selected apns-push-type, affecting the payload format.

Conclusion

The Apple Push Notification Console simplifies remote push notification testing by enabling customization of request headers and payloads. It facilitates replicating server configurations and debugging, making it a valuable tool for developers.

Reference

If you appreciate my work, please give me a round of applause. 👏.

--

--