Set up a server to generate notifications and push them to user devices.
Remote notifications (also known as push notifications) let you push small amounts of data to devices on which your app is installed, even when your app isn't running. Apps use notifications to keep the user informed. For example, a messaging service sends remote notifications when new messages arrive for the user.
The delivery of remote notifications involves several key components:
Your company's server (known as the provider server)
Apple Push Notification service (APNs)
The user's device
Your app (running on the user's device).
Remote notifications begin with your company’s server. You decide when you want to send notifications to your users. When it's time to send a notification, you generate a request containing the notification data and a unique identifier for the user's device. You then forward your request to APNs, which handles the delivery of the notification to the user’s device. Upon receipt of the notification, the operating system on the user's device handles any user interactions and delivers the notification to your app.
You're responsible for setting up a provider server (or servers) and for configuring your app to handle notifications on the user's device. (Apple manages everything in between, including the presentation of notifications to the user.) You must also have an app running on the user's device that can communicate with your server and provide needed information. For information on how to configure your app to handle remote notifications, see Registering Your App with APNs.
Build Custom Infrastructure for Notifications
Here are the main tasks for setting up a remote notification server. How you implement these tasks depends on your infrastructure, and you are free to use whatever technologies that are appropriate for your company.
Write code to receive device tokens from instances of your app running on user devices, and to associate those tokens with your users' accounts. See Registering Your App with APNs.
Determine when to send notifications to your users, and write code to generate notification payloads. See Generating a Remote Notification.
Manage a connection to APNs using HTTP/2 and TLS. See Sending Notification Requests to APNs
Write code to generate POST requests containing your payloads, and send those requests over your HTTP/2 connection. See Sending Notification Requests to APNs.
For token-based authentication, regenerate your token periodically. See Establishing a Token-Based Connection to APNs.
Establish a Trusted Connection to APNs
Communication between your provider server and APNs must take place over a secure connection. Creating that connection requires installing a GeoTrust Global CA root certificate on each of your provider servers. If your provider server runs macOS, this root certificate is in the keychain by default. On other systems, you might need to install this certificate yourself. You can download this certificate from the GeoTrust Root Certificates website.
To send notifications, your provider server must establish either token-based or certificate-based trust with APNs using HTTP/2 and TLS. Both techniques have advantages and disadvantages, so decide which technique is best suited for your company.
To set up token-based trust with APNs, see Establishing a Token-Based Connection to APNs.
To set up certificate-based trust with APNs, see Establishing a Certificate-Based Connection to APNs.
Understand What APNs Provides
APNs makes every effort to deliver your notifications, and to deliver them with the best user experience:
APNs manages an accredited, encrypted, and persistent IP connection to the user’s device.
APNs can store and forward notifications for a device that is currently offline.
APNs coalesces notifications with the same identifier.