0Pricing
Swift Academy · Lesson

Handling Notification Payloads

Respond to foreground and background notifications.

The Payload Structure

A remote notification is a JSON dictionary your server sends to APNs. The reserved aps key holds the user-visible content — alert, sound, badge — while any sibling keys carry your custom data, such as an item id to open.

// Example payload JSON:
// {
//   "aps": { "alert": { "title": "Hi", "body": "..." },
//            "sound": "default", "badge": 1 },
//   "itemId": "42"
// }

The aps Dictionary

Inside aps, alert can be a string or a title/body/subtitle object. sound, badge, and flags like content-available and mutable-content also live here. Everything outside aps is yours to define.

// aps keys:
//   alert: { title, subtitle, body }
//   sound: "default" or critical sound object
//   badge: Int
//   content-available: 1  (silent / background)
//   mutable-content: 1    (allow modification)

All lessons in this course

  1. Registering for Push Notifications
  2. Handling Notification Payloads
  3. Background Tasks and Refresh
  4. Notification Actions and Categories
← Back to Swift Academy