The center for requesting authorization to provide parental controls.
To authorize your app so that it can provide parental controls,
access the shared `AuthorizationCenter` instance.
```swift
let center = AuthorizationCenter.shared
```
> Important: You must add the Family Controls capability to your app before you call the
``FamilyControls/AuthorizationCenter/requestAuthorization(for:)``
or ``FamilyControls/AuthorizationCenter/revokeAuthorization(completionHandler:)`` methods.
This capability adds the
<doc://com.apple.documentation/documentation/bundleresources/entitlements/com_apple_developer_family-controls>
entitlement to your app.
In a compatible iPad or iPhone app running in visionOS, authorization attempts always fail.
For more information, see
<doc://com.apple.documentation/documentation/xcode/adding-capabilities-to-your-app/>.
Next, to request authorization to provide parental controls,
call ``FamilyControls/AuthorizationCenter/requestAuthorization(completionHandler:)``
``` swift
center.requestAuthorization { result in
switch result {
case .success():
// The request succeeded.
case .failure(let error):
// Handle the error here.
}
}
```
or ``FamilyControls/AuthorizationCenter/requestAuthorization(for:)``.
``` swift
do {
try await center.requestAuthorization(for: FamilyControlsMember.individual)
} catch {
// Handle the error here.
}
```
Always request authorization when your app first launches.
If the user's parent or guardian hasn't previously authorized your app,
the system displays an alert. If the parent or guardian chooses to continue,
it displays an authentication sheet.
When a parent or guardian either approves or cancels the request,
the system sends the result back to the `requestAuthorization(completionHandler:)`
method's completion handler.
If you're authenticating an `individual` who hasn't previously authorized your app,
the system displays an alert. If the `individual` chooses to continue,
the device asks to authorize that `individual` using Face ID or Touch ID.
After your app has been authorized, additional calls to `requestAuthorization(for:)`
don't display the authentication sheet or ask to authorize that individual using Face ID or Touch ID.
Instead, the system sets the authorization status.
To observe changes to the authorization status, use
the ``FamilyControls/AuthorizationCenter/authorizationStatus`` property.
The status may change due to external events,
such as a child graduating to an adult account,
or a parent or guardian changing the status in Settings.
You can also revoke authorization by calling
``FamilyControls/AuthorizationCenter/revokeAuthorization(completionHandler:)``
func revokeAuthorization(completionHandler: @escaping (Result<Void, any Error>) -> Void)
Revokes authorization to provide parental controls.
- Parameters:
- completionHandler: A closure the system calls after
it completes the authorization request.
The system passes the following parameters:
- term `result`: A value that represents either a success or a failure,
including an associated <doc://com.apple.documentation/Swift/Error> object for failures.
If your app's authentication status is ``FamilyControls/AuthorizationStatus/approved``
this method revokes authentication.
> Note: This method has no effect if your app's current authentication status is
``FamilyControls/AuthorizationStatus/denied``.
The completion handler's <doc://com.apple.documentation/documentation/Swift/Result>
parameter indicates whether the request completed successfully.
It doesn't indicate your app's authorization state.
After you revoke authorization,
your app no longer provides parental controls,
and the system no longer enforces restrictions,
such as preventing the user from deleting your app.
func requestAuthorization(completionHandler: @escaping (Result<Void, any Error>) -> Void)
Requests authorization to provide parental controls for a child.
- Parameters:
- completionHandler: A closure the system calls after
it completes the authorization request.
The system passes the following parameters:
- term `result`: A value that represents either a success or a failure,
including an associated <doc://com.apple.documentation/Swift/Error> object for failures.
With this function you can authorize parental controls for a child on a device that is part of a
Family Sharing group and signed into a child's iCloud account.
Call this method when your app first launches.
If the user's parent or guardian hasn't authorized your app previously,
this method displays an authentication sheet.
When a parent or guardian approves or cancels the request,
the system sends the result to the `requestAuthorization(completionHandler:)` method's callback handler.
After a parent or guardian authorizes your app, additional calls to `requestAuthorization(completionHandler:)`
no longer display the authentication sheet.
Instead, the system sets the authorization status and calls the completion handler directly.
The completion handler's <doc://com.apple.documentation/documentation/Swift/Result>
parameter indicates whether the request completed successfully.
It doesn't indicate your app's authorization state.
After the parent or guardian authorizes your app,
the system enacts restrictions to prevent the user from bypassing parental controls.
For example, the system prevents the user from deleting an authorized app.
In addition, as long as the device has at least one authorized app,
the user can't sign out of iCloud.
You can revoke authorization
by calling ``FamilyControls/AuthorizationCenter/revokeAuthorization(completionHandler:)``.
Requests authorization to provide parental controls for a child or individual.
- Parameters:
- member: The ``FamilyControlsMember`` that requests authorization
With this function you can authorize parental controls for a ``FamilyControlsMember/child``
that's signed into the iCloud account on the device or a ``FamilyControlsMember/individual``.
A parent or guardian must authenticate a child's account, while individuals can authenticate their own account.
For more information, see ``FamilyControlsMember``.
Call this method when your app first launches.
If the ``FamilyControlsMember/individual`` hasn't authorized your app previously,
the device tries to authorize that individual using Face ID or Touch ID.
After the user approves or cancels the request,
the system either sets the authorization status or throws an error.
After a ``FamilyControlsMember/individual`` authorizes your app, additional calls to `requestAuthorization(for:)`
no longer ask to authorize that `individual` using Face ID or Touch ID. Additionally, the system removes
any restrictions that prevent the user from bypassing parental controls so the user can delete an
authorized app or sign out of iCloud as needed.
You can revoke authorization
by calling ``FamilyControls/AuthorizationCenter/revokeAuthorization(completionHandler:)``.
get · iOS 15.0+
authorizationStatus
TypeScript
get authorizationStatus(): AuthorizationStatus
Swift declaration
@Published<AuthorizationStatus> var authorizationStatus: AuthorizationStatus { get }
The status of your app’s authorization to provide parental controls.
The initial value is always ``FamilyControls/AuthorizationStatus/notDetermined``.
The system sets this property only after a call
to ``FamilyControls/AuthorizationCenter/requestAuthorization(for:)``
succeeds. It then updates the property until a call
to ``FamilyControls/AuthorizationCenter/revokeAuthorization(completionHandler:)``
succeeds or your app exits.
To track changes to your app's authorization status,
attach a <doc://com.apple.documentation/documentation/combine/Subscriber> to the `authorizationStatus` property.
```swift
let cancellable = center.$authorizationStatus
.sink() {
switch center.authorizationStatus {
case .notDetermined:
// Handle the change to notDetermined.
case .denied:
// Handle the change to denied.
case .approved:
// Handle the change to approved.
}
}
```
Alternatively, you can assign the ``FamilyControls/AuthorizationCenter``
to an <doc://com.apple.documentation/documentation/SwiftUI/ObservedObject>
property inside a <doc://com.apple.documentation/documentation/SwiftUI/View>.
The system update the view whenever the status changes.
```swift
@ObservedObject var center = AuthorizationCenter.shared
```
The status may change due to external events,
such as a child graduating to an adult account,
or a parent or guardian changing the status in Settings.
Only access the `authorizationStatus` property
on the <doc://com.apple.documentation/documentation/Dispatch/DispatchQueue/1781006-main> queue.
get · iOS 15.0+
$authorizationStatus
TypeScript
get $authorizationStatus(): _Combine_Published_Publisher<AuthorizationStatus>
Swift declaration
var $authorizationStatus: Published<AuthorizationStatus>.Publisher { get }
get · iOS 15.0+
shared
TypeScript
static get shared(): AuthorizationCenter
Swift declaration
static let shared: AuthorizationCenter
The shared center for requesting and revoking authorization.