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

[Fix] #223 - 다이얼로그 '허용' 선택 후 토글 오류 수정 #224

Merged
merged 8 commits into from
Jan 29, 2024
2 changes: 1 addition & 1 deletion iOS-NOTTODO/iOS-NOTTODO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1846,4 +1846,4 @@
/* End XCSwiftPackageProductDependency section */
};
rootObject = 3B027A6C299C31B500BEB65C /* Project object */;
}
}
6 changes: 6 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Enum/AnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum AnalyticsEvent {
case clickOnboardingNext3(select: [String])
case clickOnboardingNext4
case clickOnboardingNext5
case clickPushAllow(section: Bool)
case clickPushReject(section: Bool)
case clickOnboardingNext6

var name: String {
Expand All @@ -36,6 +38,8 @@ enum AnalyticsEvent {
case .clickOnboardingNext3: return "click_onboarding_next_3"
case .clickOnboardingNext4: return "click_onboarding_next_4"
case .clickOnboardingNext5: return "click_onboarding_next_5"
case .clickPushAllow: return "click_push_allow"
case .clickPushReject: return "click_push_reject"
case .clickOnboardingNext6: return "click_onboarding_next_6"
}
}
Expand All @@ -47,6 +51,8 @@ enum AnalyticsEvent {
case .clickOnboardingNext3(select: let select): return ["onboard_select": select]
case .clickOnboardingNext4: return nil
case .clickOnboardingNext5: return nil
case .clickPushAllow(section: let section): return ["section": section]
case .clickPushReject(section: let section): return ["section": section]
case .clickOnboardingNext6: return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Enum/DefaultKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ struct DefaultKeys {
static let socialToken = "socialToken"
static let accessToken = "accessToken"
static let fcmToken = "fcmToken"
static let isNotificationAccepted = "isNotificationAccepted"
static let isDeprecatedBtnClicked = "isDeprecatedBtnClicked"
}
6 changes: 4 additions & 2 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Enum/KeychainUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public final class KeychainUtil {
static func getAppleEmail() -> String {
UserDefaults.standard.string(forKey: DefaultKeys.appleEmail) ?? "연동된 이메일 정보가 없습니다"
}

static func getBool(_ key: String) -> Bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로퍼티가 추가되면 계속 함수가 추가되는 구조라 제네릭을 이용한 Keychain 관련 Util을 만들어봐도 좋을것 같아요 ㅎ.ㅎ
나중에 시간나면 같이 만들어봐여,,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 좋습니다!! 이번 리팩 때 이 부분도 수정해보아요 , ,

UserDefaults.standard.bool(forKey: key)
}
static func isDeprecatedBtnClicked() -> Bool {
UserDefaults.standard.bool(forKey: DefaultKeys.isDeprecatedBtnClicked)
}

static func removeUserInfo() {
if UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) {
if getBool(DefaultKeys.isAppleLogin) {
UserDefaults.standard.removeObject(forKey: DefaultKeys.appleName)
UserDefaults.standard.removeObject(forKey: DefaultKeys.appleEmail)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

import Amplitude

class AmplitudeAnalyticsService: AnalyticsServiceProtocol {
final class AmplitudeAnalyticsService: AnalyticsServiceProtocol {
static let shared: AmplitudeAnalyticsService = AmplitudeAnalyticsService()

init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import KakaoSDKCommon
import KakaoSDKAuth
import KakaoSDKUser

class AuthViewController: UIViewController {
final class AuthViewController: UIViewController {

// MARK: - UI Components

Expand Down Expand Up @@ -276,7 +276,14 @@ extension AuthViewController {

func requestNotification() {
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { _, _ in
UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { isAllowed, _ in
KeychainUtil.setBool(isAllowed, forKey: DefaultKeys.isNotificationAccepted)
if isAllowed {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickPushAllow(section: isAllowed))
} else {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickPushReject(section: isAllowed))
}

self.presentToHomeViewController()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension NottodoModalViewController: ModalDelegate {

extension NottodoModalViewController {
func withdrawal() {
if !UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) {
if !KeychainUtil.getBool(DefaultKeys.isAppleLogin) {
kakaoWithdrawal()
}
AuthAPI.shared.withdrawalAuth { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Then
import SnapKit

class DetailStackView: UIView {
final class DetailStackView: UIView {

let verticalStackView = UIStackView()
let tagLabel = UILabel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SnapKit
final class MyInfoViewController: UIViewController {

// MARK: - Properties

typealias CellRegistration = UICollectionView.CellRegistration
typealias HeaderRegistration = UICollectionView.SupplementaryRegistration
typealias DataSource = UICollectionViewDiffableDataSource<Sections, InfoModel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ final class MyInfoAccountStackView: UIView {
let contentLabel = UILabel()
let notificationSwitch = UISwitch()
private let lineView = UIView()
var isTapped: Bool = false
private var notificationSettings: UNNotificationSettings?
var switchClosure: ((_ isTapped: Bool) -> Void)?
private var isNotificationAllowed: Bool {
return KeychainUtil.getBool(DefaultKeys.isNotificationAccepted)
}

// MARK: - View Life Cycle

init(title: String, isHidden: Bool) {
super.init(frame: .zero)
setUI(title: title, isHidden: isHidden)
setLayout(isHidden: isHidden)
UNUserNotificationCenter.current().getNotificationSettings { settings in
self.isTapped = settings.authorizationStatus == .authorized
}

NotificationCenter.default.addObserver(
self,
Expand Down Expand Up @@ -75,7 +73,7 @@ extension MyInfoAccountStackView {
}

notificationSwitch.do {
$0.isOn = isTapped
$0.isOn = isNotificationAllowed
$0.onTintColor = .green2
$0.addTarget(self, action: #selector(switchTapped), for: .valueChanged)
}
Expand Down Expand Up @@ -123,7 +121,6 @@ extension MyInfoAccountStackView {
}

@objc func switchTapped(_ sender: Any) {
AmplitudeAnalyticsService.shared.send(event: isTapped ? AnalyticsEvent.AccountInfo.completePushOn : AnalyticsEvent.AccountInfo.completePushOff)

DispatchQueue.main.async {
do {
Expand Down Expand Up @@ -161,9 +158,16 @@ extension MyInfoAccountStackView {
private func appWillEnterForeground() {
UNUserNotificationCenter.current().getNotificationSettings { [weak self] settings in
DispatchQueue.main.async {
self?.notificationSettings = settings
self?.isTapped = settings.authorizationStatus == .authorized
self?.switchClosure?(self!.isTapped)
KeychainUtil.setBool(settings.authorizationStatus == .authorized, forKey: DefaultKeys.isNotificationAccepted)
if let isNotificationAllowed = self?.isNotificationAllowed {
self?.switchClosure?(isNotificationAllowed)
}

if KeychainUtil.getBool(DefaultKeys.isNotificationAccepted) {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.AccountInfo.completePushOn)
} else {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.AccountInfo.completePushOff)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class MyInfoAccountViewController: UIViewController {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.AccountInfo.viewAccountInfo)
setUI()
setLayout()
configure(model: MyInfoAccountModel(nickname: UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) ? KeychainUtil.getAppleUsername() : KeychainUtil.getKakaoNickname(), email: UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) ? KeychainUtil.getAppleEmail() : KeychainUtil.getKakaoEmail(), account: UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) ? "apple" : "kakao", notification: true))
configure(model: MyInfoAccountModel(nickname: KeychainUtil.getBool(DefaultKeys.isAppleLogin) ? KeychainUtil.getAppleUsername() : KeychainUtil.getKakaoNickname(), email: KeychainUtil.getBool(DefaultKeys.isAppleLogin) ? KeychainUtil.getAppleEmail() : KeychainUtil.getKakaoEmail(), account: KeychainUtil.getBool(DefaultKeys.isAppleLogin) ? "apple" : "kakao", notification: true))
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ private extension MyInfoAccountViewController {

extension MyInfoAccountViewController {
func logout() {
if !UserDefaults.standard.bool(forKey: DefaultKeys.isAppleLogin) {
if !KeychainUtil.getBool(DefaultKeys.isAppleLogin) {
kakaoLogout()
}
AuthAPI.shared.deleteAuth { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class OnboardingCollectionViewCell: UICollectionViewCell {
final class OnboardingCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class SubOnboardingCollectionViewCell: UICollectionViewCell {
final class SubOnboardingCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit
import AVFoundation

class LogoOnboardingViewController: UIViewController {
final class LogoOnboardingViewController: UIViewController {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

import Lottie

class ValueOnboardingViewController: UIViewController {
final class ValueOnboardingViewController: UIViewController {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class RecommendCollectionViewCell: UICollectionViewCell {
final class RecommendCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

class RecommendViewController: UIViewController {
final class RecommendViewController: UIViewController {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class RecommendActionCollectionViewCell: UICollectionViewCell {
final class RecommendActionCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class RecommendActionFooterView: UICollectionReusableView {
final class RecommendActionFooterView: UICollectionReusableView {

// MARK: - Identifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class RecommendActionHeaderView: UICollectionReusableView {
final class RecommendActionHeaderView: UICollectionReusableView {

// MARK: - Identifier

Expand Down