You can find similar code examples in many places on the internet:
var apnsHost = "gateway.sandbox.push.apple.com";
var apnsPort = 2195;
var timeout = 3000;
using(TcpClient client = new TcpClient(AddressFamily.InterNetwork))
{
await client.ConnectAsync(apnsHost, apnsPort);
using (SslStream sslStream = new SslStream(client.GetStream(), false, _certificateValidationCallback, null))
{
try
{
sslStream.AuthenticateAsClient(apnsHost, _certificateCollection, System.Security.Authentication.SslProtocols.Tls, true);
} catch {
throw;
}
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
byte[] binaryToken = StringToByteArray(deviceToken);
writer.Write((byte)0); // The command
writer.Write((byte)0); // The first byte of the deviceId length (bit-endian first byte)
writer.Write((byte)32); // The deviceId length (big-endian second byte)
writer.Write(binaryToken);
byte[] bytesPayload = Encoding.UTF8.GetBytes(payload);
writer.Write((byte)0);
writer.Write((byte)bytesPayload.Length);
writer.Write(bytesPayload);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
}
}
While I understand that this code shakes hands with APNS, establishes a TLS connection and writes appropriate request content, I don't really understand where in this code I can specify additional Headers!
Apple describes here various headers that can be specified, and I am interested in specifying apns-expiration
and apns-priority
but I just can't figure out where and what kind of code can I fit in here to achieve my goal?