Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional priority option to allow to setting the priority of th… #20

Merged
merged 1 commit into from
Feb 7, 2020
Merged
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
24 changes: 22 additions & 2 deletions Sources/FCM/FCMApnsConfig/FCMApnsApsObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public struct FCMApnsApsObject: Codable, Equatable {
/// This string must correspond to the identifier
/// of one of the UNNotificationCategory objects you register at launch time.
public var category: String?

/// Sets the priority of the message
/// Valid values are "normal" and "high." On iOS, these correspond to APNs priorities 5 and 10.
/// For information about how to prepare sounds, see priority.
/// priority: https://firebase.google.com/docs/cloud-messaging/http-server-ref
public var priority: String?

/// The background notification flag.
/// To perform a silent background update,
Expand All @@ -38,33 +44,43 @@ public struct FCMApnsApsObject: Codable, Equatable {
/// Use your extension to modify the notification’s content.
public var mutableContent: Int?

enum Priority: String {
case normal
case high
}

enum CodingKeys: String, CodingKey {
case alert
case badge
case sound
case priority
case contentAvailable = "content-available"
case category
case threadId="thread-id"
case mutableContent="mutable-content"
}

struct Config {
var alert: FCMApnsAlertOrString?
var badge: Int?
var sound: String?
var priority: String?
var contentAvailable: Bool?
var category: String?
var threadId: String?
var mutableContent: Bool?
}

init(config: Config?) {
let contentAvailable = config?.contentAvailable ?? false
if !contentAvailable {
alert = config?.alert
badge = config?.badge
sound = config?.sound
}
if let value = config?.priority, value {
priority = value
}
if contentAvailable {
self.contentAvailable = 1
}
Expand All @@ -82,13 +98,15 @@ public struct FCMApnsApsObject: Codable, Equatable {
public init(alertString: String?,
badge: Int? = nil,
sound: String?,
priority: String? = nil,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
self.init(config: Config(alert: FCMApnsAlertOrString.fromRaw(alertString),
badge: badge,
sound: sound,
priority: priority,
contentAvailable: contentAvailable,
category: category,
threadId: threadId,
Expand All @@ -98,13 +116,15 @@ public struct FCMApnsApsObject: Codable, Equatable {
public init(alert: FCMApnsAlert? = nil,
badge: Int? = nil,
sound: String?,
priority: String? = nil,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
self.init(config: Config(alert: FCMApnsAlertOrString.fromRaw(alert),
badge: badge,
sound: sound,
priority: priority,
contentAvailable: contentAvailable,
category: category,
threadId: threadId,
Expand Down