This commit is contained in:
2025-07-19 17:43:32 -04:00
parent 2ef340e5c8
commit 33b88cb8f0
2 changed files with 18 additions and 4 deletions

View File

@ -12,9 +12,12 @@ import SwiftUI
import SwiftData
import CloudKit
import CoreData
import UIKit
@main
struct WorkoutsApp: App {
// Control whether to prevent device auto-lock
@State private var preventAutoLock: Bool = true
let container: ModelContainer
@State private var cloudKitObserver: NSObjectProtocol?
@ -23,6 +26,9 @@ struct WorkoutsApp: App {
// Set up CloudKit notification observation
setupCloudKitObservation()
// Disable screen auto-lock
UIApplication.shared.isIdleTimerDisabled = true
}
private func setupCloudKitObservation() {
@ -61,6 +67,14 @@ struct WorkoutsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
// Ensure auto-lock is disabled when app appears
UIApplication.shared.isIdleTimerDisabled = preventAutoLock
}
.onDisappear {
// Re-enable auto-lock when app disappears
UIApplication.shared.isIdleTimerDisabled = false
}
}
.modelContainer(container)
}