Skip to content

Commit 357d93b

Browse files
committed
New properties for FCMAndroidNotification (#18)
by @nerzh
1 parent d5962b6 commit 357d93b

File tree

4 files changed

+207
-1
lines changed

4 files changed

+207
-1
lines changed

Sources/FCM/FCMAndroidConfig/FCMAndroidNotification.swift

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,85 @@ public struct FCMAndroidNotification: Codable, Equatable {
4646
/// See Formatting and Styling for more information.
4747
public var title_loc_args: [String]?
4848

49+
/// The notification's channel id (new in Android O).
50+
/// The app must create a channel with this channel ID before any notification with this channel ID is received.
51+
/// If you don't send this channel ID in the request, or if the channel ID provided has not yet been created by the app,
52+
/// FCM uses the channel ID specified in the app manifest.
53+
public var channel_id: String?
54+
55+
/// Sets the "ticker" text, which is sent to accessibility services.
56+
/// Prior to API level 21 (Lollipop), sets the text that is displayed in the status bar when the notification first arrives.
57+
public var ticker: String?
58+
59+
/// When set to false or unset, the notification is automatically dismissed when the user clicks it in the panel.
60+
/// When set to true, the notification persists even when the user clicks it.
61+
public var sticky: Bool?
62+
63+
/// Set the time that the event in the notification occurred. Notifications in the panel are sorted by this time.
64+
/// A point in time is represented using protobuf.Timestamp.
65+
/// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds.
66+
/// Example: "2014-10-02T15:01:23.045123456Z".
67+
public var event_time: String?
68+
69+
/// Set whether or not this notification is relevant only to the current device.
70+
/// Some notifications can be bridged to other devices for remote display, such as a Wear OS watch.
71+
/// This hint can be set to recommend this notification not be bridged. See Wear OS guides
72+
public var local_only: Bool?
73+
74+
/// Set the relative priority for this notification.
75+
/// Priority is an indication of how much of the user's attention should be consumed by this notification.
76+
/// Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification.
77+
/// The effect of setting the same priorities may differ slightly on different platforms.
78+
/// Note this priority differs from AndroidMessagePriority.
79+
/// This priority is processed by the client after the message has been delivered,
80+
/// whereas AndroidMessagePriority is an FCM concept that controls when the message is delivered.
81+
public var notification_priority: FCMAndroidNotificationPriority?
82+
83+
/// If set to true, use the Android framework's default sound for the notification.
84+
/// Default values are specified in config.xml.
85+
public var default_sound: Bool?
86+
87+
/// If set to true, use the Android framework's default vibrate pattern for the notification.
88+
/// Default values are specified in config.xml.
89+
/// If default_vibrate_timings is set to true and vibrate_timings is also set,
90+
/// the default value is used instead of the user-specified vibrate_timings.
91+
public var default_vibrate_timings: Bool?
92+
93+
/// If set to true, use the Android framework's default LED light settings for the notification.
94+
/// Default values are specified in config.xml.
95+
/// If default_light_settings is set to true and light_settings is also set,
96+
/// the user-specified light_settings is used instead of the default value.
97+
public var default_light_settings: Bool?
98+
99+
/// Set the vibration pattern to use.
100+
/// Pass in an array of protobuf.Duration to turn on or off the vibrator.
101+
/// The first value indicates the Duration to wait before turning the vibrator on.
102+
/// The next value indicates the Duration to keep the vibrator on.
103+
/// Subsequent values alternate between Duration to turn the vibrator off and to turn the vibrator on.
104+
/// If vibrate_timings is set and default_vibrate_timings is set to true,
105+
/// the default value is used instead of the user-specified vibrate_timings.
106+
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
107+
public var vibrate_timings: [String]?
108+
109+
/// Set the Notification.visibility of the notification.
110+
public var visibility: FCMAndroidNotificationVisibility?
111+
112+
/// Sets the number of items this notification represents.
113+
/// May be displayed as a badge count for launchers that support badging.See Notification Badge.
114+
/// For example, this might be useful if you're using just one notification to represent multiple new messages
115+
/// but you want the count here to represent the number of total new messages.
116+
/// If zero or unspecified, systems that support badging use the default,
117+
/// which is to increment a number displayed on the long-press menu each time a new notification arrives.
118+
public var notification_count: Int?
119+
120+
/// Settings to control the notification's LED blinking rate and color if LED is available on the device.
121+
/// The total blinking time is controlled by the OS.
122+
public var light_settings: FCMAndroidNotificationLightSettings?
123+
124+
/// Contains the URL of an image that is going to be displayed in a notification.
125+
/// If present, it will override google.firebase.fcm.v1.Notification.image.
126+
public var image: String?
127+
49128
/// Public Initializer
50129
public init(title: String? = nil,
51130
body: String? = nil,
@@ -57,7 +136,21 @@ public struct FCMAndroidNotification: Codable, Equatable {
57136
body_loc_key: String? = nil,
58137
body_loc_args: [String]? = nil,
59138
title_loc_key: String? = nil,
60-
title_loc_args: [String]? = nil) {
139+
title_loc_args: [String]? = nil,
140+
channel_id: String? = nil,
141+
ticker: String? = nil,
142+
sticky: Bool? = nil,
143+
event_time: String? = nil,
144+
local_only: Bool? = nil,
145+
notification_priority: FCMAndroidNotificationPriority? = nil,
146+
default_sound: Bool? = nil,
147+
default_vibrate_timings: Bool? = nil,
148+
default_light_settings: Bool? = nil,
149+
vibrate_timings: [String]? = nil,
150+
visibility: FCMAndroidNotificationVisibility? = nil,
151+
notification_count: Int? = nil,
152+
light_settings: FCMAndroidNotificationLightSettings? = nil,
153+
image: String? = nil) {
61154
self.title = title
62155
self.body = body
63156
self.icon = icon
@@ -69,5 +162,19 @@ public struct FCMAndroidNotification: Codable, Equatable {
69162
self.body_loc_args = body_loc_args
70163
self.title_loc_key = title_loc_key
71164
self.title_loc_args = title_loc_args
165+
self.channel_id = channel_id
166+
self.ticker = ticker
167+
self.sticky = sticky
168+
self.event_time = event_time
169+
self.local_only = local_only
170+
self.notification_priority = notification_priority
171+
self.default_sound = default_sound
172+
self.default_vibrate_timings = default_vibrate_timings
173+
self.default_light_settings = default_light_settings
174+
self.vibrate_timings = vibrate_timings
175+
self.visibility = visibility
176+
self.notification_count = notification_count
177+
self.light_settings = light_settings
178+
self.image = image
72179
}
73180
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// FCMAndroidNotificationLightSettings.swift
3+
//
4+
//
5+
// Created by Oleh Hudeichuk on 13.12.2019.
6+
//
7+
8+
public typealias FCMAndroidNotificationLightSettingsColor = FCMAndroidNotificationLightSettings.Color
9+
10+
public struct FCMAndroidNotificationLightSettings: Codable, Equatable {
11+
/// Required. Set color of the LED with google.type.Color.
12+
public var color: Color
13+
14+
/// Required. Along with light_off_duration, define the blink rate of LED flashes.
15+
/// Resolution defined by proto.Duration
16+
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
17+
public var light_on_duration: String
18+
19+
/// Required. Along with light_on_duration, define the blink rate of LED flashes.
20+
/// Resolution defined by proto.Duration
21+
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
22+
public var light_off_duration: String
23+
24+
public init (color: Color,
25+
light_on_duration: String,
26+
light_off_duration: String) {
27+
self.color = color
28+
self.light_on_duration = light_on_duration
29+
self.light_off_duration = light_off_duration
30+
}
31+
}
32+
33+
extension FCMAndroidNotificationLightSettings {
34+
public struct Color: Codable, Equatable {
35+
public var red, green, blue, alpha: Float
36+
37+
public init (red: Float, green: Float, blue: Float, alpha: Float) {
38+
self.red = red
39+
self.green = green
40+
self.blue = blue
41+
self.alpha = alpha
42+
}
43+
}
44+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// FCMAndroidNotificationPriority.swift
3+
//
4+
//
5+
// Created by Oleh Hudeichuk on 13.12.2019.
6+
//
7+
8+
public enum FCMAndroidNotificationPriority: String, Codable, Equatable {
9+
/// If priority is unspecified, notification priority is set to PRIORITY_DEFAULT.
10+
case unspecified = "PRIORITY_UNSPECIFIED"
11+
12+
/// Lowest notification priority.
13+
/// Notifications with this PRIORITY_MIN might not be shown to the user
14+
/// except under special circumstances, such as detailed notification logs.
15+
case min = "PRIORITY_MIN"
16+
17+
/// Lower notification priority.
18+
/// The UI may choose to show the notifications smaller,
19+
/// or at a different position in the list, compared with notifications with PRIORITY_DEFAULT.
20+
case low = "PRIORITY_LOW"
21+
22+
/// Default notification priority.
23+
/// If the application does not prioritize its own notifications, use this value for all notifications.
24+
case `default` = "PRIORITY_DEFAULT"
25+
26+
/// Higher notification priority.
27+
/// Use this for more important notifications or alerts.
28+
/// The UI may choose to show these notifications larger,
29+
/// or at a different position in the notification lists, compared with notifications with PRIORITY_DEFAULT.
30+
case high = "PRIORITY_HIGH"
31+
32+
/// Highest notification priority.
33+
/// Use this for the application's most important items that require the user's prompt attention or input.
34+
case max = "PRIORITY_MAX"
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// FCMAndroidNotificationVisibility.swift
3+
//
4+
//
5+
// Created by Oleh Hudeichuk on 13.12.2019.
6+
//
7+
8+
public enum FCMAndroidNotificationVisibility: String, Codable, Equatable {
9+
/// If unspecified, default to Visibility.PRIVATE.
10+
case unspecified = "VISIBILITY_UNSPECIFIED"
11+
12+
/// Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.
13+
case `private` = "PRIVATE"
14+
15+
/// Show this notification in its entirety on all lockscreens.
16+
case `public` = "PUBLIC"
17+
18+
/// Do not reveal any part of this notification on a secure lockscreen.
19+
case secret = "SECRET"
20+
}

0 commit comments

Comments
 (0)