1.03 for iOS and 1.5.0 for Android
This commit is contained in:
@@ -4,6 +4,7 @@ struct ContentView: View {
|
||||
@StateObject private var dataManager = ClimbingDataManager()
|
||||
@State private var selectedTab = 0
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@State private var notificationObservers: [NSObjectProtocol] = []
|
||||
|
||||
var body: some View {
|
||||
TabView(selection: $selectedTab) {
|
||||
@@ -43,11 +44,23 @@ struct ContentView: View {
|
||||
.tag(4)
|
||||
}
|
||||
.environmentObject(dataManager)
|
||||
.onChange(of: scenePhase) {
|
||||
if scenePhase == .active {
|
||||
dataManager.onAppBecomeActive()
|
||||
.onChange(of: scenePhase) { oldPhase, newPhase in
|
||||
if newPhase == .active {
|
||||
// Add slight delay to ensure app is fully loaded
|
||||
Task {
|
||||
try? await Task.sleep(nanoseconds: 200_000_000) // 0.2 seconds
|
||||
dataManager.onAppBecomeActive()
|
||||
}
|
||||
} else if newPhase == .background {
|
||||
dataManager.onAppEnterBackground()
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
setupNotificationObservers()
|
||||
}
|
||||
.onDisappear {
|
||||
removeNotificationObservers()
|
||||
}
|
||||
.overlay(alignment: .top) {
|
||||
if let message = dataManager.successMessage {
|
||||
SuccessMessageView(message: message)
|
||||
@@ -62,6 +75,44 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func setupNotificationObservers() {
|
||||
// Listen for when the app will enter foreground
|
||||
let willEnterForegroundObserver = NotificationCenter.default.addObserver(
|
||||
forName: UIApplication.willEnterForegroundNotification,
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { _ in
|
||||
print("📱 App will enter foreground - preparing Live Activity check")
|
||||
Task {
|
||||
// Small delay to ensure app is fully active
|
||||
try? await Task.sleep(nanoseconds: 800_000_000) // 0.8 seconds
|
||||
await dataManager.onAppBecomeActive()
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for when the app becomes active
|
||||
let didBecomeActiveObserver = NotificationCenter.default.addObserver(
|
||||
forName: UIApplication.didBecomeActiveNotification,
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { _ in
|
||||
print("📱 App did become active - checking Live Activity status")
|
||||
Task {
|
||||
try? await Task.sleep(nanoseconds: 300_000_000) // 0.3 seconds
|
||||
dataManager.onAppBecomeActive()
|
||||
}
|
||||
}
|
||||
|
||||
notificationObservers = [willEnterForegroundObserver, didBecomeActiveObserver]
|
||||
}
|
||||
|
||||
private func removeNotificationObservers() {
|
||||
for observer in notificationObservers {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
notificationObservers.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
struct SuccessMessageView: View {
|
||||
|
||||
Reference in New Issue
Block a user