AuthorizationCenter requestAuthorization returns error 5

AuthorizationCenter.shared.requestAuthorization(for: .individual)

returns:

(lldb) po error
Error Domain=FamilyControls.FamilyControlsError Code=5 "(null)"

(lldb) po error.localizedDescription
"The operation couldn’t be completed. (FamilyControls.FamilyControlsError error 5.)"

What does this error mean?

This is on iPadOS Beta 3. Was working fine in Beta 2.


More generally, how can one debug such errors?

FamilyControlsError exists:

But not 100% sure what they map to. I tried mapping them to error codes that I've dug through in the forums but didn't seem to perfectly map.

Relevant Tweet:

  • https://twitter.com/vicvijayakumar/status/1495092161821429761

@kgaidis

Please find the error code mapping below,

enum FamilyControlsError : LocalizedError {

  case restricted   case unavailable   case invalidAccountType   case invalidArgument   case authorizationConflict   case authorizationCanceled   case networkError   @available(iOS 16.0, *)   case authenticationMethodUnavailable }

For your case error is like "The parent or guardian canceled a request for authorization."

Do one thing, remove the app and try install it again. Do you able to see the alert dialogue asking for authentication?

remove the app and try install it again. Do you able to see the alert dialogue asking for authentication?

I have tried that, and it's the same effect.

In Beta 3, Screen Time API's are not working well for me. For example, I can't even disable Screen Time restrictions for my app in Beta 3 (well, that happened before I wasn't able to enable them).

Code 5 is a FamilyControlsError.authorizationCanceled. Please see FamilyControlsError for mapping errors. Did you see a prompt requesting Face ID or device passcode? Did you cancel the prompt?

@cinnamontoast

Hi there! Thank you for your help :)

How do I know FamilyControlsError.authorizationCanceled maps to "Code 5"? I can't find a number in the docs? I might be missing something obvious?

To note, this worked in Beta 1 and Beta 2. I can't get it to work in Beta 3.

I call:

do {
   try await AuthorizationCenter.shared.requestAuthorization(for: .individual)
} catch {
}

It then prompts me: "Allow 'APP' to Manage Restrictions on This iPad"

I click "Continue."

FaceID succeeds, and it just returns the error:

Error Domain=FamilyControls.FamilyControlsError Code=5 "(null)"

@cinnamontoast

I opened FB10798095

If it indeed is a cancellation issue, then this log may be relevant:

error	2022-07-20 19:41:44.011573 -0400	FamilyControlsAuthenticationUI	Attempt to present <FamilyControlsAuthenticationUI.ConfirmationViewController: 0x103032600> on <FamilyControlsAuthenticationUI.AuthenticationUIServiceViewController: 0x10550e700> (from <FamilyControlsAuthenticationUI.AuthenticationUIServiceViewController: 0x10550e700>) whose view is not in the window hierarchy.

The code corresponds to the backwards order of the FamilyControlsErrors seen in the documentation and it starts from 0. So restricted is Code 0, unavailable is Code 1, invalidArgument is Code 2. 

If "5" is FamilyControlsError.authorizationCanceled, I am still a little confused on the order?

AuthorizationCenter requestAuthorization returns error 5
 
 
Q