A push notification is a message typically sent from a server to a device that instructs mobile applications to perform some action. Push notifications can deliver information to users on their devices when the application is in the foreground, background, or even closed. You can draw users back to your app by reminding and informing them of important notices, messages, timers, and events.
PubNub's Mobile Push Gateway bridges iOS native message publishing with the Apple Push Notification service (APNs), Apple's official notification service.
Push notifications are delivered in the following manner on the PubNub network:
The application publishes to PubNub via a channel that has a device registered to receive push notifications with the push payload.
PubNub inspects the payload. If a specific mobile payload is found, it checks for device registrations on the channel. If found, PubNub forwards the push to APNs.
APNs then delivers the push notification to one or more devices.
Watch the video below or follow the step-by-step instructions to learn how to enable iOS push notifications for your PubNub keyset, create and download an Authentication Token file associated with your Apple Developer Account, and set up/configure an example iOS project in Xcode to receive push notifications from APNs.
If you would like to follow a more detailed example, walkthrough our detailed tutorial to set up and add push notifications to an existing iOS Swift chat application built with PubNub.
Need extra information? Check out our in-depth how-to to learn more about push notifications in the PubNub network and how they can enhance your application and user experience. Be sure to also checkout PubNub’s official documentation on Mobile Push Gateway to learn more about push notifications.
Please note: You will need to connect a physical iOS device (iPhone, iPad, iPod Touch, etc) to your computer to test and receive push notifications from APNs. Simulated devices in Xcode cannot be registered in APNs, and thus cannot receive a device token, which is necessary when sending push notifications across the PubNub network.
Login to the Admin Portal.
Click on the apps tab on the left hand side of the portal.
Click on an application. You will be brought to the keysets page for this application.
Click on a keyset. You will be brought to the configuration page for this keyset.
Enable Mobile Push Notifications by clicking on the slider to turn it on. This enables the Mobile Push Gateway, the bridge between your PubNub application and notifications services like APNs.
Mobile Push Notifications Webhook Settings. These are not required for push functionality to work in your application, but are necessary to receive events on your server.
Push Device Removed Webhook: Triggers the http(s) endpoint when a device token is removed from a channel. You learn more on how to implement this in our Android documentation.
Push Error Webhook: Triggers the http(s) endpoint in case of push notification errors. You can learn more about troubleshooting push notifications in our Troubleshooting docs.
Apple Push Credentials. This setting needs to be configured to receive push notifications from APNs.
Download the latest stable version of Xcode.
Login to your Apple Developer Account with access to the Apple Developer Program. You'll need to be enrolled in this program in order to access services that allow your application to receive push notifications from APNs.
In the Program Resources section, click Certificates, IDs & Profiles.
Click on the Keys tab. You will create your APNs Authentication Token.
Register a new key by providing a name. Enable Apple Push Notifications service (APNs) by checking the checkbox. Click Continue.
Click Continue, and download the authentication token file. The format of the token file will be
Back in the Admin Portal, in the Apple Push Credentials section, you need to upload the
AuthKey_<key id>.p8 file. Enter in the Team ID found via Overview -> Membership -> Team ID and Auth Key ID found via Overview -> Certificates, IDs & Profiles -> Keys -> <key name> ->Key ID, both fields found in your Apple Developer Account.
Open your project in Xcode. Sign in using your developer account if you have not done so.
In the project navigator, click on the project file. In the Targets section, click on your project.
In the General tab, enter a unique Bundle Identifier by appending something like -
push at the end of the ID. APNs identifies your application in a provisioning profile by combining a Team ID (generated by Apple) and your Bundle Identifier as an explicit App ID to be able to use certain capabilities, including receiving push notifications for your application.
Click on the Signing & Capabilities tab.
Ensure that the checkbox for "Automatically manage signing" is checked.
In the Signing section, ensure that your developer account is selected in the Team drop-down.
Ensure the Bundle Identifier is the same as that in the General tab.
Add Push Notification support to your application by clicking on the
+ symbol, search for "push notifications", and then double click the Capability to add to your application.
At the top of the entry point of the application, such as AppDelegate.swift, ensure you add the line
import UserNotifications to be able to use push notifications in your project.
Connect your physical Apple Device to your computer. A pop-up in Xcode will ask if you want to register your device. Be sure to register to do so, as it will be linked to your Apple Developer Account.
Firebase Cloud Messaging. This setting needs to be configured to receive push notifications from the push service Firebase Cloud Messaging devices. Learn how to receive push notifications from this push service provider through our how-to, Android Kotlin tutorial, and PubNub documentation.
Microsoft Push Notifications. The setting to enable push notifications to be received on Microsoft devices. Please note that this setting is deprecated and is planned to be removed in the near future.
Click on Save Changes to save these updated changes.