APNS JSON notification creation library.
Copyright (c) 2015 Silent Circle LLC
Authors: Edwin Fine (efine@silentcircle.com
).
json_term() = [json_term()] | [{binary() | atom() | integer(), json_term()}] | #{} | true | false | null | integer() | float() | binary() | atom() | calendar:datetime()
make_notification/1 | Create a notification consisting of a JSON binary suitable for transmitting to the Apple Push Service. |
make_notification(PL) -> ApnsJsonNotification
PL = [proplists:property()]
ApnsJsonNotification = binary()
Create a notification consisting of a JSON binary suitable for transmitting to the Apple Push Service.
{'alert', binary() | proplist()}
binary()
, it will be used as the notification text. If a
proplist()
, see Alert Properties for the format of the
proplist()
.{'badge', integer()}
{'sound', binary()}
Library/Sounds
folder of the app’s data container. The sound in this
file is played as an alert. If the sound file doesn’t exist or default
is specified as the value, the default alert sound is played. The audio
must be in one of the audio data formats that are compatible with
system sounds; see
Preparing Custom Alert Sounds
for details.{'content-available', integer()}
application:didReceiveRemoteNotification:fetchCompletionHandler:
is
called.{'category', binary()}
UIMutableUserNotificationCategory
object you created
to define custom actions. To learn more about using custom actions, see
Registering Your Actionable Notification Types.{'extra', proplist()}
Additional (optional) custom data, which must be an object (Erlang proplist) as described in the table below.
json | erlang |
---|---|
number |
integer() | float() |
string |
binary() |
true |
'true' |
false |
'false' |
null |
'null' |
array |
[json()] |
empty object |
[{}] |
non-empty object |
[{binary() | atom(), json()}] |
This describes the proplist that is expected if alert
is not a binary
string (a binary string such as <<"This is a message.">>
). In the
following description, binary()
is to be interpreted as a binary string.
{'title', binary()}
{'body', binary()}
{'title-loc-key', binary() | 'null'}
Localizable.strings
file for the
current localization. The key string can be formatted with %@
and
%n$@
specifiers to take the variables specified in the 'title-loc-args'
array.
See Localized Formatted Strings
for more information. This key was added in iOS 8.2.{'title-loc-args', [binary()] | 'null'}
'title-loc-key'
.
See Localized Formatted Strings for more information.
This key was added in iOS 8.2.{'action-loc-key', binary() | 'null'}
null
, the system displays an alert with a
single OK button that simply dismisses the alert when tapped.
See
Localized Formatted Strings
for more information.{'loc-key', binary()}
Localizable.strings
file for
the current localization (which is set by the user's language
preference). The key string can be formatted with %@
and %n$@
specifiers to take the variables specified in 'loc-args'
.
See
Localized Formatted Strings
for more information.
{'loc-args', [binary()]}
'loc-key'
.
{'launch-image', binary()}
UILaunchImageFile
key in the application's
Info.plist
file, or falls back to Default.png
.
Notification = [
{'alert', <<"Would you like to play a game?">>}
].
Notification = [
{'alert', <<"Would you like to play a game?">>},
{'badge', 1},
{'sound', <<"wopr">>}
].
Notification = [
{'alert', <<"Would you like to play a game?">>},
{'extra', [{<<"meta">>, [{<<"movie">>, <<"War Games">>}]]}
].
This assumes that the Localizable.strings
file in the .lproj
directory
contains
"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";
Notification = [
{'alert', [{'title', <<"Game invite">>},
{'loc-key', <<"GAME_PLAY_REQUEST_FORMAT">>},
{'loc-args', [<<"Jenna">>, <<"Frank">>]}]},
{'sound', <<"chime">>}
].
For information on the keys in the proplist, see Local and Push Notification Programming Guide.