Skip to content

Instantly share code, notes, and snippets.

@Kjuly
Last active June 22, 2016 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kjuly/f741f9d3b2fb08c49537 to your computer and use it in GitHub Desktop.
Save Kjuly/f741f9d3b2fb08c49537 to your computer and use it in GitHub Desktop.
Registering for Remote Notifications (APN)

Client side:

An app must register with Apple Push Notification service (APNs) to receive remote notifications sent by the app’s push provider. In iOS 8 and later, registration has four stages:

  1. Register the notification types your app supports using registerUserNotificationSettings:.
  2. Register to receive push notifications via APNs by calling your app’s registerForRemoteNotifications method.
  3. Store the device token returned to the app delegate by the server for a successful registration, or handle registration failure gracefully.
  4. Forward the device token to the app’s push provider.

Server side:

Need private key (*.p12 or *.pem), key passphrase, deviceToken that get from client side everytime client connected to APNs.

Generate *.pem from *.p12 (exported from keychain, selected cert & private key, export 2 items):

$ openssl pkcs12 -in private_key.p12 -out private_key.pem -nodes -clcerts

Server send notifications to gateway below:

  • Development: gateway.sandbox.push.apple.com, outbound TCP port 2195
  • Production: gateway.push.apple.com, outbound TCP port 2195

Test APN locally via HOUSTON:

(more cmd tools: http://nomad-cli.com)

Dev:

$ apn push "<xxxxxxxx ... xxxxxxxx>" -c ~/private_key_of_apns_for_development.pem -e development -m "Hello"

Production:

$ apn push "<xxxxxxxx ... xxxxxxxx>" -c ~/private_key_of_apns_for_distribution.pem -e production -m "Hello"

Reference

Others that might helps:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment