fix 角标显示未读消息数
This commit is contained in:
parent
6fc790db68
commit
59dc41bfa7
@ -1,5 +1,8 @@
|
||||
# 基于erlang的推送服务
|
||||
|
||||
## mysql
|
||||
mysql -h127.0.0.1 -uroot -p'r3a-7Qrh#3Q'
|
||||
|
||||
## api接口
|
||||
|
||||
|
||||
@ -13,6 +16,9 @@
|
||||
"device_token": "b48b911e85874b403ce80cbb33864e8ed6f06455e80310b0f6b95e672a3e39dc",
|
||||
"title": "动物狂响曲",
|
||||
"body": "第7集(校服与被毛更深处),bilibili已更新",
|
||||
|
||||
"unread_num": 10,
|
||||
|
||||
"custom_data": {
|
||||
"target": "detail",
|
||||
"params": {
|
||||
|
||||
@ -104,8 +104,8 @@ handle_call(_Request, _From, State) ->
|
||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||
{stop, Reason :: term(), NewState :: #state{}}).
|
||||
handle_cast({push, Notifications}, State = #state{apns_pid = ApnsPid, headers = Headers}) ->
|
||||
lists:foreach(fun(#{<<"device_token">> := DeviceToken, <<"title">> := Title, <<"body">> := Body, <<"custom_data">> := CustomData}) ->
|
||||
PushResult = push_task(ApnsPid, DeviceToken, Title, Body, CustomData, Headers),
|
||||
lists:foreach(fun(#{<<"device_token">> := DeviceToken, <<"title">> := Title, <<"body">> := Body, <<"unread_num">> := UnreadNum, <<"custom_data">> := CustomData}) ->
|
||||
PushResult = push_task(ApnsPid, DeviceToken, Title, Body, UnreadNum, CustomData, Headers),
|
||||
lager:debug("[dimension_apn_pusher] device_token: ~p, push result is: ~p", [DeviceToken, PushResult])
|
||||
end, Notifications),
|
||||
{noreply, State};
|
||||
@ -144,8 +144,8 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
||||
push_task(ApnsPid, DeviceToken, Title, Body, CustomData, Headers)
|
||||
when is_pid(ApnsPid), is_binary(DeviceToken), is_binary(Title), is_binary(Body), is_map(CustomData), is_map(Headers) ->
|
||||
push_task(ApnsPid, DeviceToken, Title, Body, UnreadNum, CustomData, Headers)
|
||||
when is_pid(ApnsPid), is_binary(DeviceToken), is_binary(Title), is_binary(Body), is_integer(UnreadNum), is_map(CustomData), is_map(Headers) ->
|
||||
Notification = #{
|
||||
aps => #{
|
||||
alert => #{
|
||||
@ -156,7 +156,7 @@ push_task(ApnsPid, DeviceToken, Title, Body, CustomData, Headers)
|
||||
% 播放默认声音
|
||||
sound => <<"default">>,
|
||||
% App 图标角标
|
||||
badge => 1
|
||||
badge => UnreadNum
|
||||
% category => <<"HUB_MESSAGE">>
|
||||
},
|
||||
custom_data => CustomData
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user