%%%------------------------------------------------------------------- %%% @doc %%% %%% @end %%% Created : 31 Aug 2012 [email protected] %%%------------------------------------------------------------------- -module(test_apns). -record(apns_connection, {apple_host = "gateway.sandbox.push.apple.com" :: string(), apple_port = 2195 :: integer(), cert_file = "priv/cert.pem" :: string(), key_file = undefined :: undefined | string(), timeout = 30000 :: integer(), error_fun = fun(X,Y) -> erlang:display({X,Y}) end :: fun((binary(), apns:status()) -> stop | _), feedback_host = "feedback.sandbox.push.apple.com" :: string(), feedback_port = 2196 :: integer(), feedback_fun = fun erlang:display/1 :: fun((string()) -> _), feedback_timeout = 30*60*1000 :: pos_integer() }). -record(apns_msg, {id = apns:message_id() :: binary(), expiry = apns:expiry(86400) :: non_neg_integer(), %% default = 1 day device_token :: string(), alert = none :: none | apns:alert(), badge = none :: none | integer(), sound = none :: none | string(), extra = [] :: [apns_mochijson2:json_property()]}). -record(loc_alert, {body = none :: none | string(), action = none :: none | string(), key = "" :: string(), args = [] :: [string()], image = none :: none | string()}). push_token/1]). get_pid() -> {ok, Pid} = apns:connect(), Pid. delete_pid(ConnId) -> apns:disconnect(ConnId). push_by_pid(ConnId, Token1) -> Alert1 = #apns_msg{device_token = Token1, badge = 9, sound = "bingbong.aiff", %extra = [{"jump","yes"}], extra = [{jump, yes}], alert = #loc_alert{body="hello1" }}, io:format("In ~p:appns_packet ~p Alert1 = ~p ~n", [?MODULE, ?LINE, Alert1]), apns:send_message(ConnId, Alert1). -spec push(DeviceToken :: string(), Alert :: tuple()) -> ok. push(DeviceToken, Alert)-> Conn = apns:connect(), case Conn of {ok,ConnId} -> Res = apns:send_message(ConnId, DeviceToken, Alert), Res1 = apns:send_message(ConnId, DeviceToken, Alert), case Res of ok -> ok; Err -> Err end, apns:disconnect(ConnId); Err -> Err end.