Skip to main content

Sending APNS push notifications

To send a push notification to an iOS device using the Apple Push Notification service (APNS), you can use Tesmon's HTTP::CLIENT action. Below is a TesmonLang example that demonstrates how to send a "Hello" alert to an iOS app.

APNS Official Documentation

You can create JWT token in the APNS Push Notification Console

variables:
apnsHost: "api.sandbox.push.apple.com" # Use 'api.push.apple.com' for production
deviceToken: "your_device_token_here"
apnsPort: 443
topic: "your.app.bundle.id"
jwtToken: "your_jwt_token_here" # Assume the JWT token is already generated and available

actions:
sendApnsPushNotification:
type: HTTP::CLIENT
props:
method: POST
baseUrl: https://${{variables.apnsHost}}:${{variables.apnsPort}}
path: /3/device/${{variables.deviceToken}}
headers:
apns-topic: ${{variables.topic}}
authorization: bearer ${{variables.jwtToken}}
body: |
{
"aps": {
"alert": {
"title": "title",
"subtitle": "subtitle",
"body": "body"
}
}
}

tests

scripts:
checkNotificationSuccess: |-
response = context['last_output']
assert response['statusCode'] == 200, "Failed to send APNS notification"

tests:
test_sendPushNotification:
tasks:
- action: actions.sendApnsPushNotification
validate: scripts.checkNotificationSuccess