Push Notification – Maybe you already know?

Tram Ho

Push Notification – Maybe you already know?

Preamble

Push notification for some developers may be simple, but setting up and selecting some configs for firebase and creating certificates for it is still hard to remember for beginners.

It will be quite confusing when things do not fall into straight cases, right?

Sometimes, you may not even be able to export the required .p12 file due to a lost key or mixed product / develop environment certificate and unable to send push notifications to Testflight / App Store. Even worse, certificates often expire after 1 year and you must renew the certificate in Apple’s developer center and reload it to your service provider each year, if you have 5 apps, then you have to Show this process 5 times per year!

But that was before WWDC 2016, so what?

Fortunately, Apple acknowledged that shortcoming and weakness and introduced a new authentication format for push notifications. The new format is a .p8 key file, it works for all your applications (for example, one main file can send push notifications to all your applications), working in the develop environment. and product (no need to switch between certificates) and one basic element and better yet it doesn’t expire!

However, the security and management of this file will need a lot more attention than the .p12 file because anyone with it can push noti to all the applications on your App Store! If you suspect a lock file may be compromised, please visit the lock page and revoke it.

We will look at how to generate a .p8 key file and use it on Firebase in the next section.

Create a .p8 file

To create a .p8 key file, go to https://developer.apple.com/account/ then go to Certificates, Identifiers & Profiles and select the key

Select Register a New Key then select Apple Push Notifications service (APNs), fill it in, create and download it to your device.

The Auth Key file name will look like this: AuthKey ABCD1234.p8, with ABCD1234 being the primary ID for this key, we will need this key ID later.

That’s how to create a .p8 file

NOTE: Remember to keep the key file safe because you can only download it once, if you lose the key file, you will need to revoke it and register a new file.

Because the .p8 key file can be easily abused, I recommend not using the free online web service, requiring free push because they can keep the lock file on their server.

Use .p8 file in Firebase to push notification.

Now that we have the .p8 file, go to Firebase to configure the APNs service (Apple’s Push Notifications)

In the Firebase dashboard, select your project:

then click on the application name setting icon, select cloud messaging tab

and scroll down to the APNs Authentication Key section, then click upload to upload your .p8 key file.

In the upload dialog, there are two other fields we need to consider, namely the key ID and Team ID. As mentioned earlier, the key ID is the string behind AuthKey in the file name.

For Team ID, you can get this information on https://developer.apple.com/account/#/membership

Click ‘Upload’ and you’re done! You can now send Firebase push notifications with the main file .p8.

Your next job is to write code to handle push on the application. You can refer to the following article: https://www.raywenderlich.com/8164-push-notifications-tutorial-getting-started

Share the news now

Source : Viblo