Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.
Open
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
41 changes: 35 additions & 6 deletions Tsuchi/Classes/Tsuchi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,40 @@ public class Tsuchi: NSObject {
public static let shared = Tsuchi()
private var container: AnyContainer?
public var didRefreshRegistrationTokenActionBlock: ((String) -> Void)?
public var showsNotificationBannerOnPresenting: Bool = true

public enum NotificationOptionType {
case all
case noAlert
case noBadge
case noSound
case alertOnly
case badgeOnly
case soundOnly
case none

func getOptions() -> UNNotificationPresentationOptions {
switch self {
case .all:
return [.alert, .badge, .sound]
case .noAlert:
return [.badge, .sound]
case .noBadge:
return [.alert, .sound]
case .noSound:
return [.alert, .badge]
case .alertOnly:
return [.alert]
case .badgeOnly:
return [.badge]
case .soundOnly:
return [.sound]
case .none:
return []
}
}
}

public var notificationOptionType: NotificationOptionType = .all

private override init() {
super.init()
Expand Down Expand Up @@ -118,11 +151,7 @@ extension Tsuchi: UNUserNotificationCenterDelegate {
debugPrint("[Tsuchi] willPresent Message ID: \(userInfo["gcm.message_id"] as Any)")
debugPrint("[Tsuchi] ", userInfo)
container?.base.parse(userInfo, mode: .willPresent)
if showsNotificationBannerOnPresenting {
completionHandler([.alert, .badge, .sound])
} else {
completionHandler([.badge, .sound])
}
completionHandler(self.notificationOptionType.getOptions())
}

public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
Expand Down