I use the following code to send notification through the apple push notification api. It worked well until a few days ago when it started throwing an error:
Socket was remotely closed
This is the code that I'm using:
p8key = "*****"
private_key = OpenSSL::PKey::EC.new p8key
token = JWT.encode(
{
'iss': "*****",
'iat': DateTime.now().to_time.to_i
},
private_key,
'***',
header_fields=
{
'alg':"***",
"kid": "***"
}
)
client = NetHttp2::Client.new("https://api.push.apple.com:443")
client.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
msg = "Hello"
body = { aps: { alert: msg, sound: "sound.mp3", badge: 1 } }.to_json
request = client.call(
:post,
"/3/device/#{recipient.push_token}",
body: body,
headers:
{
'authorization' => "bearer #{token}",
"apns-topic" => "com.dogtime.dogtimeinit"
}
)
It keeps throwing the error every time I try sending a notification, any idea where it could come from?