diff --git a/HackIllinois.xcodeproj/project.pbxproj b/HackIllinois.xcodeproj/project.pbxproj index 36245ec6..9d69f88c 100644 --- a/HackIllinois.xcodeproj/project.pbxproj +++ b/HackIllinois.xcodeproj/project.pbxproj @@ -1301,7 +1301,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2022.1.2; + MARKETING_VERSION = 2024.1.3; ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" -Xfrontend -warn-long-expression-type-checking=150"; PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios; @@ -1332,7 +1332,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2022.1.2; + MARKETING_VERSION = 2024.1.3; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/HackIllinois/AppDelegate.swift b/HackIllinois/AppDelegate.swift index 34e718cc..d08e9d30 100644 --- a/HackIllinois/AppDelegate.swift +++ b/HackIllinois/AppDelegate.swift @@ -61,6 +61,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { _ = HILocalNotificationController.shared GMSServices.provideAPIKey(String(bytes: obfuscatedApiKey.deobfuscated, encoding: .utf8)!) HIApplicationStateController.shared.initalize() + // Check the app version and prompt the user to update if needed + checkAppVersion() return true } @@ -125,3 +127,62 @@ extension AppDelegate { tableViewAppearance.showsHorizontalScrollIndicator = false } } + +// MARK: - App Update Check +extension AppDelegate { + // Check version of app against version of API + func checkAppVersion() { + let apiEndpointURL = URL(string: "https://adonix.hackillinois.org/version/ios")! + + // Create an URLSession task to fetch the API version + let task = URLSession.shared.dataTask(with: apiEndpointURL) { data, response, error in + if let error = error { + NSLog("Error fetching API version: \(error)") + return + } + guard let data = data, let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { + NSLog("Invalid response or status code from API endpoint") + return + } + do { + // Parse the JSON response to obtain the API version + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], + let apiVersion = json["version"] as? String { + NSLog("API version is \(apiVersion)") + // Get the app's version from Info.plist + if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { + if appVersion.compare(apiVersion, options: .numeric) == .orderedAscending { + // App version is less than API version, prompt the user to update + self.showUpdateAlert() + } + } + } + } catch { + NSLog("Error parsing API response: \(error)") + } + } + + task.resume() + } + + func showUpdateAlert() { + let alert = UIAlertController( + title: "Update Required", + message: "A new version of the app is available. Please update to continue.", + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: "Update", style: .default, handler: { _ in + // Open the App Store page for app for the user to update + if let appURL = URL(string: "https://apps.apple.com/us/app/hackillinois/id1451755268") { + UIApplication.shared.open(appURL, options: [:], completionHandler: nil) + } + })) + DispatchQueue.main.async { + if let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) { + if let rootViewController = keyWindow.rootViewController { + rootViewController.present(alert, animated: true, completion: nil) + } + } + } + } +} diff --git a/HackIllinois/FlowControllers/HIApplicationStateController.swift b/HackIllinois/FlowControllers/HIApplicationStateController.swift index 27564cdc..809f9f9f 100644 --- a/HackIllinois/FlowControllers/HIApplicationStateController.swift +++ b/HackIllinois/FlowControllers/HIApplicationStateController.swift @@ -39,7 +39,6 @@ class HIApplicationStateController { func initalize() { window.makeKeyAndVisible() resetPersistentDataIfNeeded() - reset2023IfNeeded() recoverUserIfPossible() recoverProfileIfPossible() onboardingViewController.shouldDisplayAnimationOnNextAppearance = user == nil @@ -51,15 +50,6 @@ class HIApplicationStateController { // MARK: - API extension HIApplicationStateController { - func reset2023IfNeeded() { - let didReset = UserDefaults.standard.object(forKey: "didReset2023") as? Bool ?? false - if !didReset { - _ = Keychain.default.purge() - HICoreDataController.shared.purge() - UserDefaults.standard.set(true, forKey: "didReset2023") - logoutUser() - } - } func resetPersistentDataIfNeeded() { guard !UserDefaults.standard.bool(forKey: HIConstants.APPLICATION_INSTALLED_KEY) else { return } _ = Keychain.default.purge()