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

[Feat] #205 - 선택 업데이트 구현 #210

Merged
merged 5 commits into from
Jan 8, 2024
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: 2 additions & 2 deletions iOS-NOTTODO/iOS-NOTTODO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "nottodo.iOS-NOTTODO";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1589,7 +1589,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "nottodo.iOS-NOTTODO";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
112 changes: 101 additions & 11 deletions iOS-NOTTODO/iOS-NOTTODO/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
KakaoSDK.initSDK(appKey: Bundle.main.kakaoAPIKey)
FirebaseApp.configure()

if KeychainUtil.getAccessToken() != "" {
self.skipAuthView()
print("토큰 유효")
}
checkForUpdate()

// 메시지 대리자 설정
Messaging.messaging().delegate = self

// FCM 다시 사용 설정
Messaging.messaging().isAutoInitEnabled = true

// device token 요청.
application.registerForRemoteNotifications()

Expand Down Expand Up @@ -83,22 +80,115 @@ func application(_ application: UIApplication, didDiscardSceneSessions sceneSess

extension AppDelegate: MessagingDelegate {
/// 현재 등록 토큰 가져오기.
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let fcmToken = fcmToken {
KeychainUtil.setFcmToken(fcmToken)
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let fcmToken = fcmToken {
KeychainUtil.setFcmToken(fcmToken)
}
}
}

extension AppDelegate: UNUserNotificationCenterDelegate {

/// foreground에서 러닝 중에 앱에 도착하는 알림을 다루는 메서드
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.list, .sound, .badge, .banner])
}

/// 도착한 notification에 대한 유저의 반응을 다루는 메서드
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
}

extension AppDelegate {
func checkForUpdate() {
// 앱스토어 버전
guard let appstoreVersion = getAppstoreVersion() else { return }

// 현재 설치된 앱의 버전
guard let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else { return }

if compareVersion(userVersion: appVersion, appstoreVersion: appstoreVersion) {
DispatchQueue.main.async {
self.showUpdateAlert()
}
} else {
if KeychainUtil.getAccessToken() != "" {
self.skipAuthView()
print("토큰 유효")
}
}
}

/// 버전 비교하는 메서드
func compareVersion(userVersion: String, appstoreVersion: String) -> Bool {
let userMajor = userVersion.split(separator: ".").map {Int($0)!}[0]
let appstoreMajor = appstoreVersion.split(separator: ".").map {Int($0)!}[0]

if userMajor < appstoreMajor {
return true
}

let userMinor = userVersion.split(separator: ".").map {Int($0)!}[1]
let appstoreMinor = appstoreVersion.split(separator: ".").map {Int($0)!}[1]

if userMinor < appstoreMinor {
return true
}

let userPatch = userVersion.split(separator: ".").map {Int($0)!}[2]
let appstorePatch = appstoreVersion.split(separator: ".").map {Int($0)!}[2]

if userPatch < appstorePatch {
return true
}

return false
}

/// 앱스토어에 배포된 버전 가져오는 메서드
func getAppstoreVersion() -> String? {
let appleID = Bundle.main.appleId
guard let url = URL(string: "https://itunes.apple.com/lookup?id=\(appleID)"),
let data = try? Data(contentsOf: url),
let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any],
let results = json["results"] as? [[String: Any]],
let appStoreVersion = results[0]["version"] as? String else {
return nil
}
return appStoreVersion
}

/// 선택 업데이트 경고창
func showUpdateAlert() {
let alertController = UIAlertController(
title: I18N.update,
message: I18N.updateAlert,
preferredStyle: .alert
)

let updateAction = UIAlertAction(title: I18N.update, style: .default) { _ in
// App Store로 이동
if let appStoreURL = URL(string: "https://itunes.apple.com/app/\(Bundle.main.appleId)") {
UIApplication.shared.open(appStoreURL, options: [:], completionHandler: {_ in
if KeychainUtil.getAccessToken() != "" {
self.skipAuthView()
print("토큰 유효")
}
})
}
}

let cancelAction = UIAlertAction(title: I18N.later, style: .default)

alertController.addAction(updateAction)
alertController.addAction(cancelAction)

if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
if let keyWindow = windowScene.windows.first,
let rootViewController = keyWindow.rootViewController {
rootViewController.present(alertController, animated: true, completion: nil)
}
}
}
}
12 changes: 12 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Extensions/Bundle+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ extension Bundle {
}
return value
}

var appleId: String {
guard let filePath = Bundle.main.path(forResource: "API_KEY", ofType: "plist") else {
fatalError("Could't find file 'API_KEY.plist'.")
}
let plist = NSDictionary(contentsOfFile: filePath)

guard let value = plist?.object(forKey: "APPLE_ID") as? String else {
fatalError("Couldn't find key 'APPLE_ID' in 'API_KEY.plist'.")
}
return value
}
}
6 changes: 6 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO/Global/Literals/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ struct I18N {
static let delete = "삭제하기"
static let deleteModalTitle = "삭제하시겠습니까?"
static let deleteModalSubtitle = "한 번 삭제하면 되돌릴 수 없어요."
static let update = "업데이트"
static let updateAlert = """
최신 업데이트가 있습니다.
업데이트하시겠습니까?
"""
static let later = "나중에"
static let notiDialogTitle = """
알림을 허용하면
낫투두가 더 잘 도울 수 있어요!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ private extension MyInfoAccountViewController {
nextView.modalPresentationStyle = .overFullScreen
nextView.modalTransitionStyle = .crossDissolve
nextView.pushToRootAction = { [weak self] in
if let window = self?.view.window?.windowScene?.keyWindow {
let rootViewController = AuthViewController()
self?.navigationController?.changeRootViewController(rootViewController)
}
self?.navigationController?.changeRootViewController(AuthViewController())
}
self.present(nextView, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,9 @@ extension FifthOnboardingViewController {
@objc
private func ButtonTapped() {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext5)

if let window = view.window?.windowScene?.keyWindow {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
UIView.animate(withDuration: 0.01) {
SceneDelegate.shared?.changeRootViewControllerTo(AuthViewController())
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
UIView.animate(withDuration: 0.01) {
SceneDelegate.shared?.changeRootViewControllerTo(AuthViewController())
}
}
}
Expand Down