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

Commit

Permalink
Merge pull request #70 from timakin/feature/apns-payload-extension
Browse files Browse the repository at this point in the history
Support APNs payload extensions for `Title & Subtitle`
  • Loading branch information
cubicdaiya authored Jul 13, 2017
2 parents 1897595 + b33e014 commit e972312
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The JSON below is the request-body example.
"token" : ["xxx"],
"platform" : 1,
"message" : "Hello, iOS!",
"title": "Greeting",
"subtitle": "greeting",
"badge" : 1,
"sound" : "default",
"content_available" : false,
Expand All @@ -53,6 +55,8 @@ 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|
|message |string |message for notification |o | | |
|title |string |title for notification |- | |only iOS |
|subtitle |string |subtitle for notification |- | |only iOS |
|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 @@ -58,6 +60,8 @@ func main() {
req.Notifications[i].Tokens = append(req.Notifications[i].Tokens, *iOSToken)
req.Notifications[i].Platform = 1
req.Notifications[i].Message = "Hello, iOS!"
req.Notifications[i].Title = "Greeting"
req.Notifications[i].Subtitle = "greeting"
req.Notifications[i].Badge = 1
req.Notifications[i].Sound = "default"
req.Notifications[i].ContentAvailable = true
Expand Down

0 comments on commit e972312

Please sign in to comment.