How to Configure & Send Apple Push Notifications using PushSharp

Ghost Yang edited this page Feb 9, 2017 · 3 revisions

How to Create an APNS .p12 Certificate on Mac

The tutorial requires that you use a Mac, and that you have an Apple Developer account, with an App ID already setup.

Step 1: Login to Apple Developer Member Center

Step 1. Login to Apple Developer Member Center

Step 2: Choose your App ID

  • Select your App ID from the list (You must have already created your App ID).
  • Click Continue.

Step 2. Choose your App Id

Step 3: Choose Sandbox or Production

  • Choose either Apple Push Notification service SSL (Sandbox) or Apple Push Notification service SSL (Sandbox & Production) as the certificate type, depending on which server you need to connect to.
  • Click Continue.

It's important to choose the correct type of certificate here for what you plan on doing.

A Device Token generated by an app signed with a Development Provisioning Profile is only valid for use with the Sandbox APNS server.

A Device Token generated by an app signed with an AdHoc or AppStore Provisioning Profile is only valid for use with the Production APNS server.

NOTE: Some users have reported issues with notification delivery using the combined Apple Push Notification service SSL (Sandbox & Production) certificate when trying to send notifications to the Sandbox APNS server.

Step 2. Choose your App Id

Step 4: Information about Requesting a Certificate

  • Note the information about creating a CSR (Certificate Signing Request).
  • Click Continue.

Step 4. Information about Requesting a Certificate

Step 5: Open Keychain Access

  • Open the Keychain Access app.

Step 5. Open Keychain Access

Step 6: Create a Certificate Signing Request

  • Click the Keychain Access menu bar item
  • Open the Certificate Assistant menu sub item
  • Click the Request a Certificate From a Certificate Authority... menu sub item

Step 6. Create a Certificate Signing Request

Step 7: Enter Certificate Signing Request Details

  • Enter your email address (to be safe, make it the same as your Apple ID developer account email address).
  • Enter a Common Name (eg: your name)
  • Choose Request is: Saved to disk
  • Click Continue.

Step 7. Enter Certificate Signing Request Details

Step 8: Save the Certificate Signing Request

  • Pick a location and filename to save the request to
  • Click Save.

Step 8. Save the Certificate Signing Request

Step 9: Complete Certificate Signing Request

  • Click Done.

Step 9. Complete Certificate Signing Request

Step 10: Upload the Certificate Signing Request

  • Switch back to your browser.
  • Click Choose File...
  • Select the Certificate Signing Request file you just created and saved.
  • Click Continue.

Step 10. Upload the Certificate Signing Request

Step 11: Download the Certificate

  • Your certificate should be ready.
  • Click Download to download the certificate.
  • Open the downloaded certificate file (it should automatically open in Keychain Access, otherwise open it manually in Keychain Access)

Step 11. Download the Certificate

Step 12: Find the Certificate and Private Key

  • Find the certificate you just opened/imported in Keychain Access
  • Expand the certificate to show the Private Key

Step 12. Find the Certificate and Private Key

Step 13: Export the Private Key

  • Select only the Private Key portion of the certificate
  • Right click the Private Key portion of the certificate
  • Click Export "Common Name"... on the popup menu.

Step 13. Export the Private Key

Step 14: Choose a Location for the Exported Key

  • Choose a location and filename to export the .p12 file to
  • Click Save.

Step 14. Choose a location for the exported key

Step 15: Password Protect the .p12 File

  • Optionally choose a password for the .p12 file to protect its private key contents.
  • Click OK.

Step 15. Password Protect the .p12 File

Done!

You should now have a .p12 file that contains the private key for connecting to Apple's APNS servers. This certificate file can be used in PushSharp with the password for it.

Congratulations, you did it!

How to configure ApnsServiceBroker

Configure connections

The Connection default in ApnsServiceBroker is 1. You can change the value using ChangeScale.

this.ApnBroker = new ApnsServiceBroker(appleConfig);
this.ApnBroker.ChangeScale(10);

Configure batch size and timer

There is a timer in each connection. The timer is triggered every 750 ms or when the number of notifications in each connection reaches 1000.

var appleConfig = new ApnsConfiguration(environment,certificateData, certificateFilePwd);
appleConfig.InternalBatchSize = 2000;
appleConfig.InternalBatchingWaitPeriod = System.TimeSpan.FromMilliseconds(500);