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
4 changes: 3 additions & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name: Dev CD

on:
# develop 브랜치로 직접 푸시 했을 때
# develop 브랜치로 직접 푸시 했을 때
# 버전과 빌드 번호가 변경되었을 때
push:
branches: [develop]
paths: [**.xcodeproj/**]

jobs:
upload-testflight:
Expand Down
7 changes: 6 additions & 1 deletion SOOUM/SOOUM/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
let userInfo = notification.request.content.userInfo
self.setupOnboardingWhenTransferSuccessed(userInfo)

let options: UNNotificationPresentationOptions = [.sound, .list, .banner]
var options: UNNotificationPresentationOptions
if let isReAddedNotifications = userInfo["isReAddedNotifications"] as? Bool, isReAddedNotifications {
options = [.list]
} else {
options = [.sound, .list, .banner]
}
completionHandler(options)
}

Expand Down
50 changes: 43 additions & 7 deletions SOOUM/SOOUM/Managers/PushManager/PushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,52 @@ extension PushManager: PushManagerDelegate {
}
}

// TODO: 임시, removeDeliveredNotifications(withIdentifiers: ) 의도한 동작 X
// 모든 알림을 삭제 후 특정 알림을 제외한 알림을 재 요청한다.
func deleteNotification(notificationId: String) {
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
let matchedIds = notifications
.filter {
($0.request.content.userInfo["notificationId"] as? String) == notificationId
let current = UNUserNotificationCenter.current()

Log.debug("remove notification with userInfo ID: \(notificationId)")

current.getDeliveredNotifications { notifications in

guard notifications.isEmpty == false else {
Log.debug("No delivered notifications to remove.")
return
}

let requestsToKeep = notifications
.filter { ($0.request.content.userInfo["notificationId"] as? String) != notificationId }
.map {
let identifier = $0.request.identifier
let contentToKeep = $0.request.content.mutableCopy() as! UNMutableNotificationContent
contentToKeep.userInfo["isReAddedNotifications"] = true
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)

// 아주 짧은 시간 뒤에 다시 발송
return UNNotificationRequest(
identifier: identifier,
content: contentToKeep,
trigger: trigger
)
}
.map { $0.request.identifier }
Log.debug("Preparing to remove all notifications and re-add \(requestsToKeep.count) notifications.")

if !matchedIds.isEmpty {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: matchedIds)
current.removeAllDeliveredNotifications()
Log.debug("Called removeAllDeliveredNotifications.")

if requestsToKeep.isEmpty {
Log.debug("No notifications to re-add.")
} else {
requestsToKeep.forEach { request in
current.add(request) { error in
if let error = error {
Log.error("Error re-adding notification (ID: \(request.identifier)): \(error.localizedDescription)")
} else {
Log.debug("Successfully re-added notification (ID: \(request.identifier))")
}
}
}
}
}
}
Expand Down