Post

Replies

Boosts

Views

Activity

AuthorizationCenter.shared.authorizationStatus not WORKING!!!
XCODE: 15.2 IOS: 16.0.1 Following the document about how to track the current status of AuthorizationStatus seems to be not working on my current environment. https://developer.apple.com/documentation/familycontrols/authorizationcenter/authorizationstatus The user authorization is .individual Here is my sample code to identify if the status has changed after revoking the permission from the Settings > ScreenTime @ObservedObject var center = AuthorizationCenter.shared @Environment(\.dismiss) var dismiss @State private var isAlert = false var body: some View { VStack { Button { dismiss() } label: { Text("Close") } .buttonStyle(GrowingButton()) } VStack { Button { DispatchQueue.main.async { if center.authorizationStatus != .approved { Task { do { if #available(iOS 15.0, *) { if #available(iOS 16.0, *) { //let center = AuthorizationCenter.shared try await center.requestAuthorization(for: .individual) } } } } } else { self.isAlert = true } } } label: { Text("Validate Screen Time Permission") } .buttonStyle(GrowingButton()) .alert(isPresented: $isAlert, content: { switch center.authorizationStatus { case .notDetermined: Alert(title: Text("Screen Time not Determined")) case .denied: Alert(title: Text("Screen Time is Denied")) case .approved: Alert(title: Text("Screen Time is Approved")) @unknown default: Alert(title: Text("Unknown")) } }) } } } It will still fallback to the APPROVED state even if the permission was already revoked from ScreenTime settings. Highly appreciated if anybody from the community can help me figure out this thing to work. Thank you.
1
5
452
Mar ’24