Apple Push Notifications Service (APNS)
Setup
- Go to your Apple Developer Account
- Click "Certificates"
- Click "Keys"
- Click the "+" button
- Name the Key
- Click "Enable" on "Apple Push Notifications Service (APNs)"
- Click "Continue"
- Click "Register"
- Click "Download"
- Go to the APNS Provider Configuration
- Enter the required information
- Click "Install Provider" or "Save"
Getting APNS Tokens
With a Courier Mobile SDK
Using a Courier Mobile SDK is the best way to set this up. All Courier Mobile SDKs sync APNS tokens to Courier and will be automatically managed. This allows you to send pushes directly to a user_id
rather than APNS tokens.
Mobile SDK | APNS Token Management | Tracking Analytics |
---|---|---|
iOS | Automatic | Automatic |
Android | Not Supported | Not Supported |
React Native | Automatic | Automatic |
Flutter | Automatic | Automatic |
Without a Courier Mobile SDK
Follow Apple's Documentation to setup push notifications on your iOS device.
What APNS tokens look like:
469d754f85604fa6bcf98c4299ba9aa760a5a3b01c5ca7277342cf3fbcea5c91
You will need to sync, store, and manage your user's APNS tokens. This likely will require you to create entries in your database, deploy separate endpoints, and add extra development time that can be avoided with a Courier Mobile SDK.
If you'd like Courier delivery and click tracking, you will also need to manually make a request to the trackingUrl
.
Sending Messages
This is a common example request you can make to the send
api that shows:
providers.apn.override.body.aps.YOUR_CUSTOM_KEY
for adding custom data to your payload. This is usually used for opening a specific screen in your app when the user takes action on a push notification.providers.apn.override.body.aps
for applying iOS specific values. You can learn more about these here.
Sending to a user_id
(Recommended)
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"to": {
"user_id": "YOUR_USER_ID"
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"apn"
]
},
"providers": {
"apn": {
"override": {
"body": {
"aps": {
"alert": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"sound": "ping.aiff",
"badge": 99,
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
}
}
}
}
}
}
}'
Sending to a token
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"to": {
"apn": {
"token": "YOUR_APNS_TOKEN"
}
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"apn"
]
},
"providers": {
"apn": {
"override": {
"body": {
"aps": {
"alert": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"sound": "ping.aiff",
"badge": 99,
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
}
}
}
}
}
}
}'
Sending to multiple tokens
curl --request POST \
--url https://api.courier.com/send \
--header 'Authorization: Bearer YOUR_AUTH_KEY' \
--header 'Content-Type: application/json' \
--data '{
"message": {
"to": {
"apn": {
"tokens": ["APNS_TOKEN_ONE", "APNS_TOKEN_TWO"]
}
},
"content": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"routing": {
"method": "all",
"channels": [
"apn"
]
},
"providers": {
"apn": {
"override": {
"body": {
"aps": {
"alert": {
"title": "Hey there 👋",
"body": "Have a great day 😁"
},
"sound": "ping.aiff",
"badge": 99,
"YOUR_CUSTOM_KEY": "YOUR_CUSTOM_VALUE"
}
}
}
}
}
}
}'
Automatic Courier Mobile SDK Formatting
By default, Courier automatically formats parts of the APNS payload to make a better developer experience for you if you are working with a Courier Mobile SDK. Here you can manage the automatic APNS settings.
What this setting does:
- Creates a simple toggle to send to Apple's production or sandbox push notification environment. Production (switch is on) is used in your production app and Sandbox (switch is off) is used for testing and development. More Details
- "Attach Mutable Content" supports Courier's iOS Notification Service Extension for better push notification delivery tracking.