Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Support APNs payload extensions for Title & Subtitle #70

Merged
merged 5 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ The JSON below is the request-body example.
{
"token" : ["yyy"],
"platform" : 2,
"title": "Greeting",
"message" : "Hello, Android!",
"subtitle": "greeting",
"collapse_key" : "update",
"delay_while_idle" : true,
"time_to_live" : 10
Expand All @@ -52,7 +54,9 @@ The request-body must has the `notifications` array. There is the parameter tabl
|-----------------|------------|-----------------------------------------|--------|-------|----------------|
|token |string array|device tokens |o | | |
|platform |int |platform(iOS,Android) |o | |1=iOS, 2=Android|
|title |string |title for notification |o | |only iOS |
|message |string |message for notification |o | | |
|subtitle |string |subtitle for notification |o | |only iOS |
Copy link
Contributor

@cubicdaiya cubicdaiya Jul 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this optional? ( title, too) if it is optional (not required), the value is not o but - in required row.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, title and subtitle are optional values.
If they weren't set, only message will be displayed.

As below, these values are optional.
https://github.com/RobotsAndPencils/buford/blob/1589c179b764ddceb204a439d9bf366f04c55f9b/payload/aps.go#L37

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is optional, update the value with - in required row.

|badge |int |badge count |- |0 |only iOS |
|sound |string |sound type |- | |only iOS |
|expiry |int |expiration for notification |- |0 |only iOS. |
Expand Down
2 changes: 2 additions & 0 deletions cmd/gaurun_recover/gaurun_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func main() {
CollapseKey: logPush.CollapseKey,
DelayWhileIdle: logPush.DelayWhileIdle,
TimeToLive: logPush.TimeToLive,
Title: logPush.Title,
Subtitle: logPush.Subtitle,
Badge: logPush.Badge,
Sound: logPush.Sound,
ContentAvailable: logPush.ContentAvailable,
Expand Down
2 changes: 1 addition & 1 deletion gaurun/apns_http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewApnsServiceHttp2(client *http.Client) *push.Service {

func NewApnsPayloadHttp2(req *RequestGaurunNotification) map[string]interface{} {
p := payload.APS{
Alert: payload.Alert{Body: req.Message},
Alert: payload.Alert{Title: req.Title, Body: req.Message, Subtitle: req.Subtitle},
Badge: badge.New(uint(req.Badge)),
Sound: req.Sound,
ContentAvailable: req.ContentAvailable,
Expand Down
12 changes: 12 additions & 0 deletions gaurun/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type LogPushEntry struct {
DelayWhileIdle bool `json:"delay_while_idle,omitempty"`
TimeToLive int `json:"time_to_live,omitempty"`
// iOS
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Badge int `json:"badge,omitempty"`
Sound string `json:"sound,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"`
Expand Down Expand Up @@ -147,6 +149,14 @@ func LogPush(id uint64, status, token string, ptime float64, req RequestGaurunNo
if req.TimeToLive != 0 {
timeToLive = zap.Int("time_to_live", req.TimeToLive)
}
title := zap.Skip()
if req.Title != "" {
title = zap.String("title", req.Title)
}
subtitle := zap.Skip()
if req.Subtitle != "" {
subtitle = zap.String("subtitle", req.Subtitle)
}
badge := zap.Skip()
if req.Badge != 0 {
badge = zap.Int("badge", req.Badge)
Expand Down Expand Up @@ -178,6 +188,8 @@ func LogPush(id uint64, status, token string, ptime float64, req RequestGaurunNo
collapseKey,
delayWhileIdle,
timeToLive,
title,
subtitle,
badge,
sound,
contentAvailable,
Expand Down
2 changes: 2 additions & 0 deletions gaurun/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type RequestGaurunNotification struct {
DelayWhileIdle bool `json:"delay_while_idle,omitempty"`
TimeToLive int `json:"time_to_live,omitempty"`
// iOS
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Badge int `json:"badge,omitempty"`
Sound string `json:"sound,omitempty"`
ContentAvailable bool `json:"content_available,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions samples/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type RequestGaurunNotification struct {
DelayWhileIdle bool `json:"data_while_idle"`
TimeToLive int `json:"time_to_live"`
// iOS
Title string `json:"title"`
Subtitle string `json:"subtitle"`
Badge int `json:"badge"`
Sound string `json:"sound"`
ContentAvailable bool `json:"content_available"`
Expand Down Expand Up @@ -57,7 +59,9 @@ func main() {
if *iOSToken != "" {
req.Notifications[i].Tokens = append(req.Notifications[i].Tokens, *iOSToken)
req.Notifications[i].Platform = 1
req.Notifications[i].Title = "Greeting"
req.Notifications[i].Message = "Hello, iOS!"
req.Notifications[i].Subtitle = "greeting"
req.Notifications[i].Badge = 1
req.Notifications[i].Sound = "default"
req.Notifications[i].ContentAvailable = true
Expand Down