Skip to content

Trying Out Push Notifications

Vijay Sharma edited this page Jan 11, 2022 · 2 revisions

The demo app can be used to try out push notifications. In order to send a notification to a device, you need the follwoing pieces of data:

  • An Apple P8 Key file
  • The P8 Key's ID
  • Apple Team ID
  • App Bundle Identifier
  • Device Token

Where to Get The P8 Key File, P8 Key ID, and Apple Team ID

You must first create an App ID Configuration in your Apple developer account that has push notifications enabled.

Next, create a new "Key" from your Apple developer account. Make sure to enable the "Apple Push Notifications service (APNs)", and register your new key.

After registering the key, you will only be able to dowload the key once, it will be a .p8 file. This file is required by your server to send notifications through Apple's APNs server. Make sure to also note the Key ID, as you'll need it along with the downloaded .p8 file.

Finally you'll need your Team ID, which can be accessed in the "Membership" section of your Apple developer account.

Where to Get The App Bundle Identifier and Device Token

The App Bundle Identifier is easily copied from the Xcode project.

Note that the bundle identifier should match the one created in your Apple developer account above.

Finally, the device token can only be retrieved when the app is run on actual device. Install the app on a device, and navigate to the "More section", then tapping on "Push Notifications".

Tapping the "Register for Push Notifications" button will present you with a dialog to accept notifications from this app. The device and app ID is then registered with Apple's APNs, and returns a device token. Copy this token.

Sending Notifications Locally

With all of the above pieces of data collected, you can now send notifications to this specific device. The simplest way to test sending a notification would be to use this tool.

Be sure to select iOS > Token from the UI, and select the P8 file downloaded earlier. Fill in the fields for Key ID, Team ID, Bundle Identifier, and Device Token.

Note, in the example below, the "Production" Environemnt is selected. This is because the Apple Certificate used to sign the app is a "Distribuition Certificate" used to sign an Ad-Hoc app. If a "Development Certificate" were used, you would need to select the "Sandbox" Environment. Therefore, if you're testing push notifications on a device that's connected to Xcode, you will have to use the "Sandbox" Environment. Similarly, if you're signing your app with an Enterprise Profile, you will have to use a "Distribution Certificate", which means you'll have to select the "Production" Environment.

Before clicking send, either quit, or close the App from your device.

Click "Send", and you should reveice a notification as follows

Sending Notifications From Your Server

Apple provides an API which you can read about here that will allow you to send notifications from your server.

ALternatively, there are libraries available for many langugages which support sending notifications to Apple's APNs.