Article

Pushing Background Updates to Your App

Deliver notifications that wake your app and update it in the background.

Overview

If your app’s server-based content changes infrequently or at irregular intervals, you can use background notifications to notify your app when new content becomes available. A background notification is a remote notification that doesn’t display an alert, play a sound, or badge your app’s icon. It wakes your app in the background and gives it time to initiate downloads from your server and update its content.

Enable the Remote Notifications Capability

To receive background notifications, your app must support the remote notifications background mode. You configure this mode in the Capabilities tab of your project, as shown in Figure 1.

Figure 1

Enabling the remote notifications background mode

Enabling the remote notification background mode in your project’s Capabilities tab.

Create a Background Notification

To send a background notification, create a remote notification with an aps dictionary that includes only the content-available key, as shown in Listing 1. You may include custom keys in the payload, but the aps dictionary must not contain any keys that would trigger user interactions.

Listing 1

Sample payload for a background notification

{
   "aps" : {
      "content-available" : 1
   },
   "acme1" : "bar",
   "acme2" : 42
}

Additionally, the notification’s POST request should contain the apns-push-type header field, with a value of background. The APNs server requires this header field when sending push notifications to Apple Watch, and recommends it for all platforms. For more information, see Create and Send a POST Request to APNs.

When a device receives a background notification, the system wakes your app in the background. On iOS it calls your app delegate’s application(_:didReceiveRemoteNotification:fetchCompletionHandler:) method. On watchOS, it calls your extension delegate’s didReceiveRemoteNotification(_:fetchCompletionHandler:) method. Your app has 30 seconds to perform any tasks and call the provided completion handler. For more information, see Handling Notifications and Notification-Related Actions.

See Also

Server Tasks

Generating a Remote Notification

Send notifications to the user’s device with a JSON payload.

Sending Notification Requests to APNs

Send your remote notification payload and device token information to APNs.