Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Packages
/*.xcodeproj
Package.resolved
/.swiftpm
79 changes: 77 additions & 2 deletions Sources/FCM/FCMAndroidConfig/FCMAndroidNotification.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

public struct FCMAndroidNotification: Codable, Equatable {

/// The notification's title.
/// If present, it will override FCMNotification.title.
public var title: String?

/// The notification's body text.
/// If present, it will override FCMNotification.body.
public var body: String?

/// The notification's icon. Sets the notification icon to myicon for drawable resource myicon.
/// If you don't send this key in the request,
/// FCM displays the launcher icon specified in your app manifest.
Expand Down Expand Up @@ -46,6 +48,50 @@ public struct FCMAndroidNotification: Codable, Equatable {
/// See Formatting and Styling for more information.
public var title_loc_args: [String]?

/// The notification's channel id (new in Android O). The app must create a channel with this channel ID before any notification with this channel ID is received. 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, FCM uses the channel ID specified in the app manifest.
public var channel_id: String?

/// Sets the "ticker" text, which is sent to accessibility services. Prior to API level 21 (Lollipop), sets the text that is displayed in the status bar when the notification first arrives.
public var ticker: String?

/// When set to false or unset, the notification is automatically dismissed when the user clicks it in the panel. When set to true, the notification persists even when the user clicks it.
public var sticky: Bool?

/// Set the time that the event in the notification occurred. Notifications in the panel are sorted by this time. A point in time is represented using protobuf.Timestamp.
/// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
public var event_time: String?

/// Set whether or not this notification is relevant only to the current device. Some notifications can be bridged to other devices for remote display, such as a Wear OS watch. This hint can be set to recommend this notification not be bridged. See Wear OS guides
public var local_only: Bool?

/// Set the relative priority for this notification. Priority is an indication of how much of the user's attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The effect of setting the same priorities may differ slightly on different platforms. Note this priority differs from AndroidMessagePriority. This priority is processed by the client after the message has been delivered, whereas AndroidMessagePriority is an FCM concept that controls when the message is delivered.
public var notification_priority: FCMAndroidNotificationPriority?

/// If set to true, use the Android framework's default sound for the notification. Default values are specified in config.xml.
public var default_sound: Bool?

/// If set to true, use the Android framework's default vibrate pattern for the notification. Default values are specified in config.xml. If default_vibrate_timings is set to true and vibrate_timings is also set, the default value is used instead of the user-specified vibrate_timings.
public var default_vibrate_timings: Bool?

/// If set to true, use the Android framework's default LED light settings for the notification. Default values are specified in config.xml. If default_light_settings is set to true and light_settings is also set, the user-specified light_settings is used instead of the default value.
public var default_light_settings: Bool?

/// Set the vibration pattern to use. Pass in an array of protobuf.Duration to turn on or off the vibrator. The first value indicates the Duration to wait before turning the vibrator on. The next value indicates the Duration to keep the vibrator on. Subsequent values alternate between Duration to turn the vibrator off and to turn the vibrator on. If vibrate_timings is set and default_vibrate_timings is set to true, the default value is used instead of the user-specified vibrate_timings.
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
public var vibrate_timings: [String]?

/// Set the Notification.visibility of the notification.
public var visibility: FCMAndroidNotificationVisibility?

/// Sets the number of items this notification represents. May be displayed as a badge count for launchers that support badging.See Notification Badge. For example, this might be useful if you're using just one notification to represent multiple new messages but you want the count here to represent the number of total new messages. If zero or unspecified, systems that support badging use the default, which is to increment a number displayed on the long-press menu each time a new notification arrives.
public var notification_count: Int?

/// Settings to control the notification's LED blinking rate and color if LED is available on the device. The total blinking time is controlled by the OS.
public var light_settings: FCMAndroidNotificationLightSettings?

/// Contains the URL of an image that is going to be displayed in a notification. If present, it will override google.firebase.fcm.v1.Notification.image.
public var image: String?

/// Public Initializer
public init(title: String? = nil,
body: String? = nil,
Expand All @@ -57,7 +103,22 @@ public struct FCMAndroidNotification: Codable, Equatable {
body_loc_key: String? = nil,
body_loc_args: [String]? = nil,
title_loc_key: String? = nil,
title_loc_args: [String]? = nil) {
title_loc_args: [String]? = nil,
channel_id: String? = nil,
ticker: String? = nil,
sticky: Bool? = nil,
event_time: String? = nil,
local_only: Bool? = nil,
notification_priority: FCMAndroidNotificationPriority? = nil,
default_sound: Bool? = nil,
default_vibrate_timings: Bool? = nil,
default_light_settings: Bool? = nil,
vibrate_timings: [String]? = nil,
visibility: FCMAndroidNotificationVisibility? = nil,
notification_count: Int? = nil,
light_settings: FCMAndroidNotificationLightSettings? = nil,
image: String? = nil
) {
self.title = title
self.body = body
self.icon = icon
Expand All @@ -69,5 +130,19 @@ public struct FCMAndroidNotification: Codable, Equatable {
self.body_loc_args = body_loc_args
self.title_loc_key = title_loc_key
self.title_loc_args = title_loc_args
self.channel_id = channel_id
self.ticker = ticker
self.sticky = sticky
self.event_time = event_time
self.local_only = local_only
self.notification_priority = notification_priority
self.default_sound = default_sound
self.default_vibrate_timings = default_vibrate_timings
self.default_light_settings = default_light_settings
self.vibrate_timings = vibrate_timings
self.visibility = visibility
self.notification_count = notification_count
self.light_settings = light_settings
self.image = image
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// FCMAndroidNotificationLightSettings.swift
//
//
// Created by Oleh Hudeichuk on 13.12.2019.
//

public struct FCMAndroidNotificationLightSettingsColor: Codable, Equatable {

public var red: Float

public var green: Float

public var blue: Float

public var alpha: Float
}

public struct FCMAndroidNotificationLightSettings: Codable, Equatable {

/// Required. Set color of the LED with google.type.Color.
public var color: FCMAndroidNotificationLightSettingsColor

/// Required. Along with light_off_duration, define the blink rate of LED flashes. Resolution defined by proto.Duration
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
public var light_on_duration: String

/// Required. Along with light_on_duration, define the blink rate of LED flashes. Resolution defined by proto.Duration
/// A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
public var light_off_duration: String
}

27 changes: 27 additions & 0 deletions Sources/FCM/FCMAndroidConfig/FCMAndroidNotificationPriority.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// FCMAndroidNotificationPriority.swift
//
//
// Created by Oleh Hudeichuk on 13.12.2019.
//

public enum FCMAndroidNotificationPriority: String, Codable, Equatable {

/// If priority is unspecified, notification priority is set to PRIORITY_DEFAULT.
case unspecified = "PRIORITY_UNSPECIFIED"

/// Lowest notification priority. Notifications with this PRIORITY_MIN might not be shown to the user except under special circumstances, such as detailed notification logs.
case min = "PRIORITY_MIN"

/// Lower notification priority. The UI may choose to show the notifications smaller, or at a different position in the list, compared with notifications with PRIORITY_DEFAULT.
case low = "PRIORITY_LOW"

/// Default notification priority. If the application does not prioritize its own notifications, use this value for all notifications.
case `default` = "PRIORITY_DEFAULT"

/// Higher notification priority. Use this for more important notifications or alerts. The UI may choose to show these notifications larger, or at a different position in the notification lists, compared with notifications with PRIORITY_DEFAULT.
case high = "PRIORITY_HIGH"

/// Highest notification priority. Use this for the application's most important items that require the user's prompt attention or input.
case max = "PRIORITY_MAX"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// FCMAndroidNotificationVisibility.swift
//
//
// Created by Oleh Hudeichuk on 13.12.2019.
//

public enum FCMAndroidNotificationVisibility: String, Codable, Equatable {

/// If unspecified, default to Visibility.PRIVATE.
case unspecified = "VISIBILITY_UNSPECIFIED"

/// Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.
case `private` = "PRIVATE"

/// Show this notification in its entirety on all lockscreens.
case `public` = "PUBLIC"

/// Do not reveal any part of this notification on a secure lockscreen.
case secret = "SECRET"
}