Skip to content

Instantly share code, notes, and snippets.

@natefinch
Created February 6, 2017 01:58
Show Gist options
  • Save natefinch/c106e9094437b34661f9418062316d86 to your computer and use it in GitHub Desktop.
Save natefinch/c106e9094437b34661f9418062316d86 to your computer and use it in GitHub Desktop.
apple push notification go struct
package notif
// Apple is a go-ification of the json struct for sending Apple Push
// Notifications, defined here:
// https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
type Apple struct {
// Include this key when you want the system to display a standard alert or
// a banner. The notification settings for your app on the user’s device
// determine whether an alert or banner is displayed.
Alert *AppleAlert `json:"alert,omitempty"`
// Include this key when you want the system to modify the badge of your app
// icon. If this key is not included in the dictionary, the badge is not
// changed. To remove the badge, set the value of this key to 0.
Badge *int `json:"badge,omitempty"`
// Include this key when you want the system to play a sound. The value of
// this key is the name of a sound file in your app’s main bundle or in the
// Library/Sounds folder of your app’s data container. If the sound file
// cannot be found, or if you specify defaultfor the value, the system plays
// the default alert sound.
Sound string `json:"sound,omitempty"`
// Include this key with a value of 1 to configure a silent notification.
// When this key is present, the system wakes up your app in the background
// and delivers the notification to its app delegate.
ContentAvailable int `json:"content-available,omitempty"`
// Provide this key with a string value that represents the notification’s
// type. This value corresponds to the value in the identifier property of
// one of your app’s registered categories.
Category string `json:"category"`
// Provide this key with a string value that represents the app-specific
// identifier for grouping notifications. The system groups notifications
// with the same thread identifier together in Notification Center and other
// system interfaces.
ThreadID string `json:"thread-id"`
}
// AppleAlert is a go-ification of the json struct defined here:
// https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
type AppleAlert struct {
// A short string describing the purpose of the notification. Apple Watch
// displays this string as part of the notification interface. This string
// is displayed only briefly and should be crafted so that it can be
// understood quickly. This key was added in iOS 8.2.
Title string `json:"title"`
// The text of the alert message.
Body string `json:"body"`
// The key to a title string in the 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 Localizing the
// Content of Your Remote Notifications for more information. This key was added
// in iOS 8.2.
TitleLocKey string `json:"title-loc-key,omitempty"`
// Variable string values to appear in place of the format specifiers in
// title-loc-key. See Localizing the Content of Your Remote Notifications for
// more information. This key was added in iOS 8.2.
TitleLocArgs []string `json:"title-loc-args,omitempty"`
// If a string is specified, the system displays an alert that includes the
// Close and View buttons. The string is used as a key to get a localized string
// in the current localization to use for the right button’s title instead of
// “View”. See Localizing the Content of Your Remote Notifications for more
// information.
ActionLocKey string `json:"action-loc-key,omitempty"`
// A key to an alert-message string in a 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 the loc-args array. See Localizing the Content of Your Remote
// Notifications for more information.
LocKey string `json:"loc-key"`
// Variable string values to appear in place of the format specifiers in
// loc-key. See Localizing the Content of Your Remote Notifications for more
// information.
LocArgs []string `json:"loc-args,omitempty"`
// The filename of an image file in the app bundle, with or without the filename
// extension. The image is used as the launch image when users tap the action
// button or move the action slider. If this property is not specified, the
// system either uses the previous snapshot, uses the image identified by the
// UILaunchImageFile key in the app’s Info.plist file, or falls back to
// Default.png.
LaunchImage string `json:"launch-image"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment