Private Sub SendMessage(Topic() As Byte, Title() As Byte, Body() As Byte)
'Dim BC As ByteConverter
HttpJob.Initialize(BC.StringFromBytes(Topic))
Dim buffer(300) As Byte 'must be large enough to hold the message payload
Dim raf As RandomAccessFile
raf.Initialize(buffer, True)
WriteBytes(raf, "{""data"":{""title"":""")
WriteBytes(raf, Title)
WriteBytes(raf, """,""body"":""")
WriteBytes(raf, Body)
WriteBytes(raf, """}")
'end of data
WriteBytes(raf, ",""to"":""\/topics\/")
WriteBytes(raf, Topic)
WriteBytes(raf, """")
WriteBytes(raf, ",""priority"": 10")
If BC.StartsWith(Topic, "ios_") Then
WriteBytes(raf, ",""notification"": {""title"": """)
WriteBytes(raf, Title)
WriteBytes(raf, """,""body"":""")
WriteBytes(raf, Body)
WriteBytes(raf, """, ""sound"": ""default""}")
End If
WriteBytes(raf, "}")
HttpJob.AddHeader("Authorization", JoinBytes(Array("key=".GetBytes, API_KEY)))
HttpJob.AddHeader("Content-Type", "application/json")
Log("stack: ", StackBufferUsage, ", buffer size:", raf.CurrentPosition)
HttpJob.Post("https://fcm.googleapis.com/fcm/send", BC.SubString2(buffer, 0, raf.CurrentPosition))
End Sub