-
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.
BaseFeature의 싱글톤 객체가 담당하도록 구현
- Loading branch information
Showing
7 changed files
with
87 additions
and
74 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
File renamed without changes.
77 changes: 77 additions & 0 deletions
77
project/Projects/Presentation/Feature/Base/Sources/Util/RemoteNotificationAuthHelper.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,77 @@ | ||
// | ||
// RemoteNotificationAuthHelper.swift | ||
// BaseFeature | ||
// | ||
// Created by choijunios on 10/9/24. | ||
// | ||
|
||
import Foundation | ||
import UserNotifications | ||
|
||
|
||
import RxSwift | ||
|
||
|
||
public enum RemoteNotificationApproveAction: Equatable { | ||
case openSystemSetting | ||
case granted | ||
case error(message: String) | ||
} | ||
|
||
public class RemoteNotificationAuthHelper { | ||
|
||
public static let shared: RemoteNotificationAuthHelper = .init() | ||
|
||
private init() { } | ||
|
||
public func checkPushNotificationApproved() -> Single<Bool> { | ||
Single<Bool>.create { single in | ||
let center = UNUserNotificationCenter.current() | ||
center.getNotificationSettings { settings in | ||
switch settings.authorizationStatus { | ||
case .notDetermined, .denied: | ||
single(.success(false)) | ||
case .authorized, .provisional, .ephemeral: | ||
single(.success(true)) | ||
@unknown default: | ||
single(.success(false)) | ||
} | ||
} | ||
|
||
return Disposables.create { } | ||
} | ||
} | ||
|
||
public func requestNotificationPermission() -> Maybe<RemoteNotificationApproveAction> { | ||
Maybe<RemoteNotificationApproveAction>.create { maybe in | ||
|
||
let current = UNUserNotificationCenter.current() | ||
|
||
current.getNotificationSettings { [maybe] settings in | ||
switch settings.authorizationStatus { | ||
case .notDetermined: | ||
// Request permission since the user hasn't decided yet. | ||
current.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in | ||
if error != nil { | ||
maybe(.success(.error(message: "알람동의를 수행할 수 없습니다."))) | ||
} else { | ||
maybe(.success(.granted)) | ||
} | ||
} | ||
case .denied: | ||
// 사용자가 요청을 거부했던 상태로 설정앱을 엽니다. | ||
maybe(.success(.openSystemSetting)) | ||
return | ||
case .authorized, .provisional, .ephemeral: | ||
maybe(.success(.granted)) | ||
default: | ||
maybe(.completed) | ||
break | ||
} | ||
} | ||
|
||
return Disposables.create { } | ||
} | ||
} | ||
} | ||
|
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
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