-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] #244 - notificationCenter & UIApplication extension 추가
- Loading branch information
1 parent
ad50ab6
commit 24b0fbb
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
iOS-NOTTODO/iOS-NOTTODO/Global/Extensions/NotificationCenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// NotificationCenter.swift | ||
// iOS-NOTTODO | ||
// | ||
// Created by JEONGEUN KIM on 3/21/24. | ||
// | ||
|
||
import UIKit | ||
import Combine | ||
|
||
extension NotificationCenter { | ||
|
||
enum Notification { | ||
case willEnterForeground | ||
case didEnterBackground | ||
} | ||
|
||
var willEnterForeground: AnyPublisher<NotificationCenter.Notification, Never> { | ||
publisher(for: UIApplication.willEnterForegroundNotification) | ||
.map { _ in return .willEnterForeground } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
var didEnterBackground: AnyPublisher<NotificationCenter.Notification, Never> { | ||
publisher(for: UIApplication.didEnterBackgroundNotification) | ||
.map { _ in return .didEnterBackground } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
var applicationState: AnyPublisher<NotificationCenter.Notification, Never> { | ||
Publishers.Merge(willEnterForeground, didEnterBackground) | ||
.eraseToAnyPublisher() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
iOS-NOTTODO/iOS-NOTTODO/Global/Extensions/UIApplication+.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// UIApplication+.swift | ||
// iOS-NOTTODO | ||
// | ||
// Created by JEONGEUN KIM on 3/21/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIApplication { | ||
private static let notificationSettingsURL: URL? = { | ||
let settingsString: String | ||
if #available(iOS 16, *) { | ||
settingsString = UIApplication.openNotificationSettingsURLString | ||
} else if #available(iOS 15.4, *) { | ||
settingsString = UIApplicationOpenNotificationSettingsURLString | ||
} else { | ||
settingsString = UIApplication.openSettingsURLString | ||
} | ||
return URL(string: settingsString) | ||
}() | ||
|
||
func openAppNotificationSettings() { | ||
guard | ||
let url = UIApplication.notificationSettingsURL, | ||
self.canOpenURL(url) else { return } | ||
return open(url) | ||
} | ||
} |