---
title: "Handle permission requests in flows - iOS"
description: "Ask users for push notification permission from a flow in your iOS app with AdaptySystemRequestsHandler, and return their answer to the flow."
---

> **AI agents**: to search Adapty docs faster and with fewer tokens, install the Adapty skills: `npx adapty skills install --yes`

A [flow](adapty-flow-builder) can ask users for permission to send push notifications with the **Request permission** action, for example on an onboarding screen that explains what the notifications are for. The Adapty SDK doesn't show the system permission dialog itself. It passes the request to an `AdaptySystemRequestsHandler` in your app. Your app shows the dialog and returns the user's answer, and the flow continues.

## Before you start

You need:

- **Adapty iOS SDK 4.0.0 or later**: Earlier versions don't have `AdaptySystemRequestsHandler`.
- **A flow with the Request permission action**: In the Flow & Paywall Builder, add the **Request permission** action to an element's **On Tap** or **On Screen Appear** trigger. In its **After response** section, add the actions to run after the user answers, such as **Navigate Next**. For the action settings, see [Request permission](onboarding-actions#request-permission).

## How the flow requests a permission

1. The flow reaches the **Request permission** action: the user taps the element, or the screen appears.
2. The Adapty SDK calls `handlePermission(_:withCustomArgs:)` on your handler with `.push`.
3. Your app requests the permission from iOS and returns `.granted` or `.denied`.
4. The flow runs the **After response** actions. They are the same for both answers.

The flow waits on the screen until your app returns the answer. If your app never answers, the flow stays on the screen. If iOS doesn't show the dialog, for example because the user already answered it, your app gets the answer at once, and the flow runs the **After response** actions right away. If those actions leave the screen, the user sees the screen that requests the permission only for a moment.

With **On Screen Appear**, the flow doesn't send the request again when the user comes back to the screen with a **Navigate back** action. With **On Tap**, every tap sends a new request, except taps while a request waits for your answer.

## Implement the handler

To answer permission requests, create a class that conforms to `AdaptySystemRequestsHandler` and implement `handlePermission(_:withCustomArgs:)`. Return `.denied` for the permissions your app doesn't request.

```swift showLineNumbers title="Swift"
import AdaptyUI
import UserNotifications

@MainActor
final class PushPermissionHandler: AdaptySystemRequestsHandler {
    func handlePermission(
        _ permission: AdaptyPermission,
        withCustomArgs customArgs: [String: String]?
    ) async -> AdaptyPermissionResult {
        guard permission == .push else { return .denied(nil) }

        do {
            let granted = try await UNUserNotificationCenter.current()
                .requestAuthorization(options: [.alert, .badge, .sound])
            return granted ? .granted(nil) : .denied(nil)
        } catch {
            return .denied(error.localizedDescription)
        }
    }
}
```

`handlePermission(_:withCustomArgs:)` receives:

- **`permission`**: The permission the flow requests. The **Request permission** action sends `.push`.
- **`customArgs`**: Custom arguments of the request. The **Request permission** action sends none, so the value is `nil`.

`.granted` and `.denied` take an optional string with details. You can pass `nil`.

A granted permission lets your app show notifications. To receive push notifications, register the device with APNs and send the device token to your push provider, as your app does outside flows.

`AdaptySystemRequestsHandler` also declares `handleAppReviewRequest()`. Its default implementation shows the App Store review prompt, so you don't need to implement it.

## Pass the handler to the flow configuration

:::warning
**Without a handler, the flow stops at the permission request.** If you don't pass `systemRequestsHandler`, iOS shows no dialog. The flow stays on the screen that sent the request and doesn't run the **After response** actions.
:::

To send the flow's permission requests to your handler, pass the handler in the `systemRequestsHandler` parameter of `AdaptyUI.getFlowConfiguration`:

```swift showLineNumbers title="Swift"
let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
    forFlow: flow,
    systemRequestsHandler: PushPermissionHandler()
)
```

The flow configuration keeps a strong reference to the handler, so you don't need to store one. Both SwiftUI and UIKit present the flow from this configuration, so the handler works with either. For details, see [Display flows & paywalls](ios-present-paywalls).

## Test the permission request

iOS shows the notification dialog only once per app install. To see the dialog again while you test the flow, delete the app from the device and install it again. Then open the flow and reach the **Request permission** action. If the screen stays and no dialog appears, the flow got no answer: make sure that you pass `systemRequestsHandler` to `AdaptyUI.getFlowConfiguration`.