-
Notifications
You must be signed in to change notification settings - Fork 7
/
alert.go
67 lines (57 loc) · 3.26 KB
/
alert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package apns2
// Alert If this property is included, the system displays a standard alert or a banner, based
// on the user’s setting. You can specify a string or a dictionary as the value of alert.
type Alert 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,omitempty"`
// The text of the alert message.
Body string `json:"body,omitempty"`
// 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 Localized Formatted Strings 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 Localized Formatted Strings 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 Localized Formatted Strings
// 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 Localized Formatted
// Strings for more information.
LocKey string `json:"loc-key,omitempty"`
// Variable string values to appear in place of the format specifiers in loc-key. See Localized Formatted Strings for more information.
LocArgs []string `json:"loc-args,omitempty"`
// The filename of an image file in the app bundle; it may include the extension or omit it.
// 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.
// This property was added in iOS 4.0.
LaunchImage string `json:"launch-image,omitempty"`
}
// “The following payload has an aps dictionary with a simple, recommended form
// for alert messages with the default alert buttons (Close and View).
// It uses a string as the value of alert rather than a
// dictionary. This payload also has a custom array property.
/*
{
"aps" : { "alert" : "Message received from Bob" },
"acme2" : [ "bang", "whiz" ]
}
*/
func (a *Alert) isSimpleForm() bool {
return len(a.Title) == 0 && len(a.TitleLocKey) == 0 && len(a.TitleLocArgs) == 0 && len(a.ActionLocKey) == 0 && len(a.LocKey) == 0 && len(a.LocArgs) == 0 && len(a.LaunchImage) == 0
}
// Returns bool if alert is valid
func (a *Alert) isValid() bool {
return a.isSimpleForm() && len(a.Body) == 0
}