Skip to content

Sending push notifications to your app with cURL (curl)

   

How to send push notifications to iOS devices with the curl command.

Create a PEM file that includes both the certificate and the private key.

$ openssl pkcs12 -in xxxx.p12 -nodes -out certificate-and-privatekey.pem

The curl command is used to send a push notification.
Push payloads, topics, and debit tokens should be from your environment.
Also, be aware that the domain (https://api.push.apple.com/3/device/ or https://api.development.push.apple.com) is different between the production environment (e.g. test flights) and the development environment.

# Production Server
$ curl -v -d '{"aps":{"alert":"hello"}}' -H "apns-topic: com.swiswiswift.myapp" --http2 --cert certificate-and-privatekey.pem https://api.push.apple.com/3/device/{your_device_token}
# Staging Server
$ curl -v -d '{"aps":{"alert":"hello"}}' -H "apns-topic: com.swiswiswift.myapp" --http2 --cert certificate-and-privatekey.pem https://api.development.push.apple.com/3/device/{your_device_token}

  1. Retrieving a certificate and private key from a P12 file
  2. Update cocoapods installed with gem.
  3. I had a chance to speak at iOSDCJapan2019 Day 1 in the Rookies LT slot.
  4. Changing the height of a TableView cell (Swift5.0.1)
  5. UIButton, display a button (Swift5.0)
  6. Using UISlider to retrieve a value at regular intervals (Swift5.0)
  7. Getting a value with UISlider (Swift5.0)