Enabling Push Notifications in Xcode project
- Choose View → Navigators → Show Project Navigator.
- Choose the target from the Project/Targets pop-up menu or in the Targets section of the second sidebar if it appears.
- Click Capabilities to view app services you can add to your app.
- In the Capabilities pane, if Push Notifications isn’t enabled, click the switch in the Push Notifications section.
- In Member Center, the Push Notifications service will appear as Configurable (not Enabled) until you create a client SSL certificate (option 2).
From Push Notifications for WordPress version 5.1 onwards we suggest you to enable HTTP/2-based Apple Push Notification service (APNs) to establish a Token-Based connection (option 1).
Option 1: obtain an Encryption Key and Key ID from Apple
You need an APNs authentication token signing key to generate the tokens used by your server. One token is enough to distribute notifications for all of your company’s apps, allows your app to connect to both the development and production environments and doesn't expire.
To create the private key:
- Go to your Apple's dev center.
- In Certificates, Identifiers & Profiles, select Keys from the sidebar
- Click the Add button (+) in the upper-left corner.
- Under Key Description, enter a unique name for the key.
- Select the checkbox next to the capabilities you want to enable, then click Continue.
- Review the key configuration, then click Confirm.
- Click Download to generate and download the key, it is saved as a text file with a
.p8
file extension in the Downloads folder. - Click Done.
- Proceed with Configure Push Notifications for WordPress
WARNING: Save this file in a secure place because the key is not saved in your developer account and you won’t be able to download it again. If the Download button is disabled, you previously downloaded the key.
Option 2: creating a Universal Push Notification Client SSL Certificate
You use Member Center to generate a push notification client SSL certificate that allows your notification server to connect to the APNs. Each App ID is required to have its own client SSL certificate. The client SSL certificate Member Center generates is a universal certificate that allows your app to connect to both the development and production environments.
To generate a universal client SSL certificate:
- Go to your Apple's dev center.
- In Certificates, Identifiers & Profiles, select Certificates.
- Click the Add button (+) in the upper-right corner.
- Under Production, select the "Apple Push Notification service SSL (Sandbox & Production)" checkbox, and click Continue.
- Choose the explicit App ID that matches your bundle ID from the App ID pop-up menu, and click Continue.
- Follow the instructions on the next webpage to create a certificate request on your Mac, and click Continue.
- Click Choose File.
- In the dialog that appears, select the certificate request file (with a
.certSigningRequest
extension), and click Choose. - Click Generate.
- Click Download and save the file (
aps.cer
). - Click Done.
Generate the SSL certificate for Push Notifications for WordPress
- Load
aps.cer
in the Keychain Access double-clicking on it. - From the Keychain Access application select the certificate (search for "Apple Push Services") and press the right mouse button.
- Select "Export" and save it as
Certificates.p12
using a password that you remember. - From the command line, in the same directory where you have saved the certificates enter this command:
$ openssl x509 -in aps.cer -inform der -out Cert.pem
- Then, from the same position enter this:
$ openssl pkcs12 -nocerts -out Key.pem -in Certificates.p12
It will ask an import password (the one you have used in step 3) and then a secure password for the certificate (the one you will use in Push Notifications for WordPress). - At this point merge the certificate and the key together:
$ cat Cert.pem Key.pem > ck.pem
Theck.pem
file will be the one you have to use in Push Notifications for WordPress.
Configure Push Notifications for WordPress
If you have followed option 1, then:
- Go to Push Notifications → Settings → iOS tab.
- Check Use HTTP/2-based Apple Push Notification service (APNs)
- Enter the Bundle ID of your app.
- Enter the Key ID generated.
- Enter your team ID.
- Paste the content of the
p8
file you have generated, as is. - Click Save Settings.
Else you have to follow those steps for option 2:
- Go to Push Notifications → Settings → iOS tab.
- Click the Upload button.
- Drag and drop the
ck.pem
file generated. - Click Select.
- Enter the password you have selected for the certificate.
- Click Save Settings.
With the new certificate system implemented by Apple you can use the same certificate both in distribution and development.
Renew a Universal Push Notification Client SSL Certificate
To renew a universal push notification client SSL certificate:
- Go to your Apple's dev center.
- In Certificates, Identifiers & Profiles, select App IDs.
- Choose the explicit App ID that matches your App ID from the pop-up menu, and click Edit.
- Press Create Certificate... under Production SSL Certificate, follow the instructions on the next webpage to create a certificate request on your Mac, and click Continue.
- Click Choose File.
- In the dialog that appears, select the certificate request file (with a
.certSigningRequest
extension), and click Choose. - Click Generate.
- Click Download and save the file (
aps.cer
). - Click Done.
Then follow Generate the SSL certificate for Push Notifications for WordPress and Configure Push Notifications for WordPress to use the renewed certificate in Push Notifications for WordPress.