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