How to send a push notification using Erlang?

前端 未结 3 634
离开以前
离开以前 2021-01-30 11:25

I\'m trying to send a push notification to APNs using Erlang. This is the code I came up with so far:

-module(apnstest2).
-export([connect/0]).

connect() ->
         


        
3条回答
  •  走了就别回头了
    2021-01-30 12:01

    I see two mistakes:

    • Token should be passed in binary and not in hex ascii.
    • You can't use the binary syntax to turn lists into binaries.

    For parsing hex to an integer and then down to binary use something like this:

    Token = "dead",
    TokenNum = erlang:list_to_integer(Token, 16),
    TokenBin = <>,
    

    Build the protocol packet with something like this:

    TokenBin = ...,
    Payload = <<"Payload">>,
    PayloadSize = byte_size(Payload),
    Packet = <<0:8, 32:16, TokenBin/binary, PayloadSize:16, Payload/binary>>,
    

提交回复
热议问题