Should I use HTTP / 2.0 to send Apple Push notifications? Can i use libcurl?

This question, as you may have deduced from the title, actually consists of two questions.

First question: Should I use HTTP / 2.0 to send Apple Push notifications?

In the Apple API API APNs documentation, the opening paragraphs indicate:

The API provider is based on the HTTP / 2 network protocol.

There are several other links to HTTP / 2.0 throughout the documentation. However, I do not see (which does not mean that it does not exist) nothing indicating that HTTP / 2.0 should be used. Does this mean that I am allowed to use any HTTP version? Or am I actually limited to HTTP / 2.0?

I am very familiar with HTTP / 1.1, but I know almost nothing about HTTP / 2.0, so if I can use my old familiar protocol, I would prefer that.

Second question (based on the first question): Is it possible to use libcurl with APN?

This question only matters with an affirmative answer to the first question. If it is not, that I should use HTTP / 2.0 with APN, then I already know that I can use libcurl.

I will send a lot of APNs from an already loaded server, and I would prefer to do it initially - so I plan to use libcurl if possible. However, I understand that libcurl is somewhat limited when it comes to HTTP / 2.0.

The main problem is that when libcurl creates an HTTP / 2.0 connection, it actually starts with an HTTP / 1.1 request that includes the upgrade header and then waits for the 101 Switching Protocols status bar 101 Switching Protocols . Is this behavior supported by APN? Or should I try using something like nghttp2 ?

I found that nghttp2 is somewhat complex and very poorly documented at the moment. I'm worried that if I can't use libcurl, I may need to implement HTTP / 2.0 myself using sockets (which will be THE WORST).

Any help is appreciated on any issue! Thanks everyone!

+8
libcurl backwards-compatibility apple-push-notifications
source share
3 answers

OK, after a long time I finally found the answer. Yes, HTTP / 2 is required to use APNS .

This boils down to one line in APNS docs that say

APNs require the use of HPACK (header compression for HTTP / 2), which prevents duplicate keys and header values.

which implies that HTTP / 2 is a required part of the protocol.

+6
source

As of now, Apple still supports its legacy API v2 (binary), which works via HTTPS, so HTTP / 2 is only required if you want to use the latest API.

The inherited API is documented in the application, but frankly, compared to the HTTP / 2 API, it is so terrible that I cannot recommend using it.

I can confidently say that the outdated API is supported because I have production code that uses it right now (I can also say that the API is terrible and I'm busy porting it to HTTP / 2).

+3
source

An example script using curl to send an http2 push message. Given that you have an authentication key on the dev site and your curl version is compiled with http2 support. p8 file should be in the same script folder as apns.sh file apns.sh Run> bash apns.sh

 #!/bin/bash deviceToken=96951ABACECA47F34C2F93D8E58591054E6F2B42691B4EADA6935C19A107A524 authKey="./AuthKey_SLDFJSDLB.p8" authKeyId=SLDFJSDLB teamId=ABCDET bundleId=com.mycompany.myapp endpoint=https://api.development.push.apple.com apns_collapse_id="score_update" read -r -d '' payload <<-'EOF' { "aps": { "badge": 2, "category": "mycategory", "alert": { "title": "my title", "subtitle": "my subtitle", "body": "my body text message 103" } }, "custom": { "mykey": "myvalue" } } EOF # -------------------------------------------------------------------------- base64() { openssl base64 -e -A | tr -- '+/' '-_' | tr -d = } sign() { printf "$1"| openssl dgst -binary -sha256 -sign "$authKey" | base64 } time=$(date +%s) header=$(printf '{ "alg": "ES256", "kid": "%s" }' "$authKeyId" | base64) claims=$(printf '{ "iss": "%s", "iat": %d }' "$teamId" "$time" | base64) jwt="$header.$claims.$(sign $header.$claims)" curl --verbose \ --header "content-type: application/json" \ --header "authorization: bearer $jwt" \ --header "apns-topic: $bundleId" \ --header "apns-collapse-id: $apns_collapse_id"\ --http2 \ --data "$payload" \ $endpoint/3/device/$deviceToken 
0
source

All Articles