diff --git a/iOS/Delegates/AppDelegate+PhasedInitialization.swift b/iOS/Delegates/AppDelegate+PhasedInitialization.swift index 48843a2..2ea8c93 100644 --- a/iOS/Delegates/AppDelegate+PhasedInitialization.swift +++ b/iOS/Delegates/AppDelegate+PhasedInitialization.swift @@ -87,53 +87,50 @@ extension AppDelegate { func initializeComponentsWithCrashProtection() { Debug.shared.log(message: "Initializing components with crash protection", type: .info) - // Use try-catch blocks to prevent crashes during initialization - do { - // Phase 1 - safe to run immediately - setupPhaseOne() + // Use structured error handling to prevent crashes during initialization + // Phase 1 - safe to run immediately + setupPhaseOne() + + // Phase 2 - defer slightly + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in + guard let self = self else { return } - // Phase 2 - defer slightly - DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in - guard let self = self else { return } - - // Use try-catch to prevent crashes in Phase 2 - do { - self.setupPhaseTwo() - } catch { - Debug.shared.log(message: "Error in Phase 2 initialization: \(error.localizedDescription)", type: .error) - } - } + // Execute Phase 2 setup + self.setupPhaseTwo() + } + + // Phase 3 - defer significantly and only if memory allows + DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in + guard let self = self else { return } - // Phase 3 - defer significantly and only if memory allows - DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in - guard let self = self else { return } - - // Check memory before heavy operations - if self.shouldProceedWithMemoryCheck() { - // Use try-catch to prevent crashes in Phase 3 - do { - self.setupPhaseThree() - } catch { - Debug.shared.log(message: "Error in Phase 3 initialization: \(error.localizedDescription)", type: .error) + // Check memory before heavy operations + if self.shouldProceedWithMemoryCheck() { + // Execute Phase 3 setup + self.setupPhaseThree() + } else { + Debug.shared.log(message: "Skipping Phase 3 due to high memory usage", type: .warning) + } + } + + // Post initialization complete notification after all phases + DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) { + NotificationCenter.default.post(name: .appInitializationCompleted, object: nil) + Debug.shared.log(message: "App initialization complete", type: .success) + } + + // Ensure UI is responsive regardless of initialization state + DispatchQueue.main.async { + // Use UIWindowScene.windows on iOS 15+ instead of deprecated UIApplication.shared.windows + if #available(iOS 15.0, *) { + if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, + let rootVC = windowScene.windows.first?.rootViewController { + rootVC.view.isUserInteractionEnabled = true } } else { - Debug.shared.log(message: "Skipping Phase 3 due to high memory usage", type: .warning) - } - } - - // Post initialization complete notification after all phases - DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) { - NotificationCenter.default.post(name: .appInitializationCompleted, object: nil) - Debug.shared.log(message: "App initialization complete", type: .success) - } - } catch { - // Log error but continue app launch with minimal functionality - Debug.shared.log(message: "Critical error during initialization: \(error.localizedDescription)", type: .error) - - // Ensure UI is still responsive even if initialization fails - DispatchQueue.main.async { - if let rootVC = UIApplication.shared.windows.first?.rootViewController { - rootVC.view.isUserInteractionEnabled = true + // Fallback for older iOS versions + if let rootVC = UIApplication.shared.windows.first?.rootViewController { + rootVC.view.isUserInteractionEnabled = true + } } } } diff --git a/iOS/Extensions/CALayer+Shadow.swift b/iOS/Extensions/CALayer+Shadow.swift new file mode 100644 index 0000000..501f6d4 --- /dev/null +++ b/iOS/Extensions/CALayer+Shadow.swift @@ -0,0 +1,21 @@ +import UIKit + +extension CALayer { + /// Apply a blue tinted shadow effect to the layer + func applyBlueTintedShadow() { + masksToBounds = false + shadowColor = UIColor.systemBlue.cgColor + shadowOffset = CGSize(width: 0, height: 4) + shadowOpacity = 0.2 + shadowRadius = 8 + } + + /// Apply a futuristic shadow effect to the layer + func applyFuturisticShadow() { + masksToBounds = false + shadowColor = UIColor(red: 0.1, green: 0.6, blue: 1.0, alpha: 1.0).cgColor + shadowOffset = CGSize(width: 0, height: 3) + shadowOpacity = 0.3 + shadowRadius = 10 + } +} \ No newline at end of file diff --git a/iOS/Extensions/UITabBar+LED.swift b/iOS/Extensions/UITabBar+LED.swift new file mode 100644 index 0000000..e49d0cb --- /dev/null +++ b/iOS/Extensions/UITabBar+LED.swift @@ -0,0 +1,14 @@ +import UIKit + +extension UITabBar { + /// Add LED effect to the tab bar with simplified parameters + @objc func addTabBarLEDEffect(color: UIColor) { + // Call the full implementation with default values + addFlowingLEDEffect( + color: color, + intensity: 0.3, + width: 2, + speed: 5.0 + ) + } +} \ No newline at end of file diff --git a/iOS/Extensions/UIView+LED.swift b/iOS/Extensions/UIView+LED.swift index b7bd8ea..2f5bd28 100644 --- a/iOS/Extensions/UIView+LED.swift +++ b/iOS/Extensions/UIView+LED.swift @@ -94,7 +94,7 @@ extension UIView { /// - intensity: Glow intensity (0.0-1.0, default: 0.8) /// - width: Width of the flowing LED effect (default: 5) /// - speed: Animation speed - lower is faster (default: 2.0) - func addFlowingLEDEffect( + @objc func addFlowingLEDEffect( color: UIColor, intensity: CGFloat = 0.8, width: CGFloat = 5, diff --git a/iOS/Extensions/UIView+UIHelpers.swift b/iOS/Extensions/UIView+UIHelpers.swift index 070bdcb..a4252cb 100644 --- a/iOS/Extensions/UIView+UIHelpers.swift +++ b/iOS/Extensions/UIView+UIHelpers.swift @@ -206,11 +206,7 @@ extension UIView { /// Apply futuristic shadow effect to the view func applyFuturisticShadow() { - layer.masksToBounds = false - layer.shadowColor = UIColor.systemBlue.cgColor - layer.shadowOffset = CGSize(width: 0, height: 4) - layer.shadowOpacity = 0.2 - layer.shadowRadius = 8 + layer.applyBlueTintedShadow() } } diff --git a/iOS/Operations/CoreML/CoreMLManager.swift b/iOS/Operations/CoreML/CoreMLManager.swift index 077703f..9ef89be 100644 --- a/iOS/Operations/CoreML/CoreMLManager.swift +++ b/iOS/Operations/CoreML/CoreMLManager.swift @@ -482,7 +482,9 @@ final class CoreMLManager { let model = try MLModel(contentsOf: compiledModelURL) // Remove observer as loading succeeded - NotificationCenter.default.removeObserver(memoryObserver) + if let observer = memoryObserver { + NotificationCenter.default.removeObserver(observer as Any) + } // Dismiss loading alert DispatchQueue.main.async { @@ -497,7 +499,9 @@ final class CoreMLManager { } } catch { // Remove observer on failure - NotificationCenter.default.removeObserver(memoryObserver) + if let observer = memoryObserver { + NotificationCenter.default.removeObserver(observer as Any) + } // Dismiss loading alert DispatchQueue.main.async { diff --git a/iOS/Views/TabbarView.swift b/iOS/Views/TabbarView.swift index c2fa30c..06ef739 100644 --- a/iOS/Views/TabbarView.swift +++ b/iOS/Views/TabbarView.swift @@ -249,41 +249,27 @@ struct TabbarView: View { // Set up LED effects after a delay to ensure tab bar is ready DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { // Apply flowing LED effect to all tab bars - safely - do { - if #available(iOS 15.0, *) { - // Use UIWindowScene.windows on iOS 15+ - UIApplication.shared.connectedScenes - .compactMap { $0 as? UIWindowScene } - .flatMap { $0.windows } - .compactMap { $0.rootViewController as? UITabBarController } - .forEach { tabController in - // Check if the method exists before calling it - if tabController.tabBar.responds(to: #selector(UITabBar.addFlowingLEDEffect)) { - tabController.tabBar.addFlowingLEDEffect( - color: UIColor(hex: "#FF6482"), - intensity: 0.3, // Reduced intensity - width: 2, - speed: 5.0 - ) - } - } - } else { - // Use deprecated windows property on older iOS versions - UIApplication.shared.windows.compactMap { $0.rootViewController as? UITabBarController } - .forEach { tabController in - // Check if the method exists before calling it - if tabController.tabBar.responds(to: #selector(UITabBar.addFlowingLEDEffect)) { - tabController.tabBar.addFlowingLEDEffect( - color: UIColor(hex: "#FF6482"), - intensity: 0.3, // Reduced intensity - width: 2, - speed: 5.0 - ) - } - } - } - } catch { - Debug.shared.log(message: "Error applying LED effect: \(error.localizedDescription)", type: .error) + if #available(iOS 15.0, *) { + // Use UIWindowScene.windows on iOS 15+ + UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .flatMap { $0.windows } + .compactMap { $0.rootViewController as? UITabBarController } + .forEach { tabController in + // Use the method directly since it's defined in our extension + tabController.tabBar.addTabBarLEDEffect( + color: UIColor(hex: "#FF6482") + ) + } + } else { + // Use deprecated windows property on older iOS versions + UIApplication.shared.windows.compactMap { $0.rootViewController as? UITabBarController } + .forEach { tabController in + // Use the method directly since it's defined in our extension + tabController.tabBar.addTabBarLEDEffect( + color: UIColor(hex: "#FF6482") + ) + } } } }