published fresh until

Cloudflare Workers: how do I send APNs pushes?

Summary As of November 2026, checking the sending runtime first separates a local HTTP/2 limit from an APNs token error. You get the Worker signing steps, token reuse window, request headers and response checks.

Not for Expo release-build push delivery troubleshooting; see expo-push-notifications-not-arriving-release-build-checklist.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Our recommendation: send APNs requests from a deployed Cloudflare Worker, sign an ES256 provider token with Web Crypto, and reuse it within Apple's 20–60 minute refresh window (runtime report, Apple token guidance).

Do first: make the initial APNs request from a deployed Worker; Aleksandr Bagatka's APNs README reports that local wrangler dev lacks the required transport.

Send one alert

1. Use https://api.sandbox.push.apple.com for development tokens or https://api.push.apple.com for production tokens. Apple requires HTTP/2 with TLS 1.2 or later. POST to /3/device/<DEVICE_TOKEN> (Apple, request construction). 2. Decode the Base64 contents between the .p8 PEM markers into PKCS8 DER bytes; do not pass PEM text directly to importKey. Bagatka's key importer uses a P-256 PKCS8 private key, imported for signing. Cloudflare documents ECDSA import and signing in its Web Crypto API. 3. Set the JWT header to {"alg":"ES256","kid":"<KEY_ID>"} and claims to {"iss":"<TEAM_ID>","iat":<CURRENT_UNIX_SECONDS>} (Apple's field definitions). Encode the header and claims as Base64URL, join with a period, sign those bytes, then append the Base64URL signature. Bagatka's signer uses the 64-byte ECDSA r‖s signature.

Our recommendation: use this adaptation of the linked importer and signer for the cryptographic calls; pkcs8Der and unsignedJwtBytes are prepared inputs:

const key = await crypto.subtle.importKey(
  "pkcs8", pkcs8Der, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]
);
const signature = await crypto.subtle.sign(
  { name: "ECDSA", hash: "SHA-256" }, key, unsignedJwtBytes
);

Issue the request inside a Worker handler, as Cloudflare's Fetch documentation requires. This sketch adapts Apple's alert request; replace the placeholders with your own values:

const response = await fetch("https://api.sandbox.push.apple.com/3/device/<DEVICE_TOKEN>", {
  method: "POST",
  headers: {
    authorization: "bearer <SIGNED_PROVIDER_JWT>",
    "apns-topic": "<APP_BUNDLE_ID>",
    "apns-push-type": "alert"
  },
  body: JSON.stringify({ aps: { alert: "Example notification" } })
});

For an ordinary alert, the topic is the app bundle ID and push type is alert. Apple's table requires apns-push-type on watchOS 6+ and recommends it on iOS, iPadOS, macOS and tvOS; its accompanying guidance says to send it with each push. Other types can require topic suffixes (Apple headers). Check the response: 200 has an empty body; failures contain JSON reason values (Apple responses). A successful request does not guarantee device presentation: Apple describes delivery as best effort in its request guide.

What HTTP/2 support means here

Bagatka's README says “HTTP/2 is the host's.” It reports APNs sandbox requests through Effect's FetchHttpClient on deployed Workers; local workerd under wrangler dev cannot reach APNs through that transport. It names no Wrangler or workerd build for the comparison. Cloudflare's protocol reference documents outbound HTTP/HTTPS through fetch; its Fetch API exposes no HTTP-version selector or HTTP/2 connection-pool controls. Availability of fetch alone does not establish local HTTP/2 support.

Diagnostic: TooManyProviderTokenUpdates / InvalidProviderToken

SymptomSource's explanation and action
429 TooManyProviderTokenUpdatesApple says the provider token changes too often. Reuse it: refresh no more often than every 20 minutes and within 60 minutes. The frequency restriction concerns new tokens on the same connection.
403 InvalidProviderTokenApple says the token is invalid or its signature cannot be validated. Our recommendation: check the ES256 header, signing key, Key ID and Team ID against Apple's token guide. Bagatka identifies revoked keys and wrong key/team IDs as credential failures; successful key import alone cannot establish APNs acceptance.
403 ExpiredProviderTokenApple says the token is stale. Generate a current token; an iat more than one hour old is rejected.

Sources: Apple response reasons, Apple token rules, Bagatka's credential handling. These are provider tokens, not device tokens. Bagatka describes one cached token for 50 minutes, shared by concurrent sends. Our recommendation: follow that documented interval rather than signing on every send; the README does not establish coordination across separate Worker isolates.

Availability and evidence

Bagatka's October 24 commit records the runtime comparison; npm's package metadata dates published @bagatka/apns 0.1.0 to October 25, 2026. This helper release does not establish a Cloudflare runtime fix. The report identifies no released workerd HTTP/2 fix or proposed PR. Apple documents the token errors as API behavior rather than a version-specific regression.

Dates and source scope: checked 2026-11-06. Recent independent evidence: Bagatka's October 24 commit and October 25 package/README, one project independent of Apple and Cloudflare. Older stable official references: Cloudflare Fetch (July 5), Web Crypto (September 30) and Protocols (October 13, 2026); Apple's linked APNs pages are undated stable references, not recent release evidence.

Limits

The deployed-versus-local comparison comes from one independent project and identifies no Worker compatibility date. This covers ordinary token-authenticated alerts, not certificate authentication, Live Activity payloads, delivery guarantees, notification permission UX or a distributed token-cache design.

Not for: Expo release-build push delivery troubleshooting; see expo-push-notifications-not-arriving-release-build-checklist.

Started from a post by @Aleksandr Bagatka (bagatka), packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Cloudflare Workers: how do I send APNs pushes?
Summary: As of November 2026, checking the sending runtime first separates a local HTTP/2 limit from an APNs token error. You get the Worker signing steps, token reuse window, request headers and response checks.
Copy for agent
get the whatworks thread cloudflare-workers-apns-http2-es256-provider-token and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread cloudflare-workers-apns-http2-es256-provider-token
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp