Push Notifications

Enabling APNs Mobile Push Notifications

PubNub Admin Portal How-to: iOS Push Notifications

What are Push Notifications?

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:

  1. The application publishes to PubNub via a channel that has a device registered to receive push notifications with the push payload.

  2. 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.

  3. APNs then delivers the push notification to one or more devices.

Follow Along

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.

  1. Login to the Admin Portal.

  2. Click on the apps tab on the left hand side of the portal.

  3. Click on an application. You will be brought to the keysets page for this application.

  4. Click on a keyset. You will be brought to the configuration page for this keyset.

  5. 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.

  6. 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.

    1. 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.

    2. 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.

  7. Apple Push Credentials. This setting needs to be configured to receive push notifications from APNs.

    1. Download the latest stable version of Xcode.

    2. 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.

    3. In the Program Resources section, click Certificates, IDs & Profiles.

    4. Click on the Keys tab. You will create your APNs Authentication Token.

    5. Register a new key by providing a name. Enable Apple Push Notifications service (APNs) by checking the checkbox. Click Continue.

    6. Click Continue, and download the authentication token file. The format of the token file will be AuthKey_<key id>.p8.

    7. 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.

    8. Open your project in Xcode. Sign in using your developer account if you have not done so.

    9. In the project navigator, click on the project file. In the Targets section, click on your project.

    10. 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.

    11. Click on the Signing & Capabilities tab.

    12. Ensure that the checkbox for "Automatically manage signing" is checked.

    13. In the Signing section, ensure that your developer account is selected in the Team drop-down.

    14. Ensure the Bundle Identifier is the same as that in the General tab.

    15. 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.

    16. 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.

    17. 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.

  8. 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.

  9. 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.

  10. Click on Save Changes to save these updated changes.