Mac hosting guide

Notification Permission UI Tests on macOS

Register addUIInterruptionMonitor, trigger requestAuthorization, tap the host app to drain the monitor, then poll UNAuthorizationStatus. It needs a logged-in macOS session and works on any Mac with remote desktop.

Figment editorial teamPublished Updated Facts checked November 10, 2026

Figment Mac plans

US East. Pay before use. Hourly and daily too.

Intel Mac VM4 shared vCPUs, 4GB RAM, 80GB SSD$25per monthApple Silicon Mac VM4 shared vCPUs, 4GB RAM, 65GB SSD$39per monthDedicated M4 Pro12-core CPU, 24GB RAM, 512GB SSD$199per month

Minimum first purchase: $25 of account credit, used for your rental.

Register addUIInterruptionMonitor before launching the app, call requestAuthorization(options:), force XCTest to drain pending interruptions with a follow-up interaction on the host app, then poll getNotificationSettings in an XCTestExpectation until UNAuthorizationStatus matches your assertion. Keep screenshots as XCTAttachment with .keepAlways so Xcode retains them for passing runs. Apple references: Asking permission to use notifications and XCUIApplication.

Where does the permission dialog come from?

From a system process, not your app. UNUserNotificationCenter.current().requestAuthorization(options:) makes the system notification daemon present a modal. XCUITest can interact with it on macOS through addUIInterruptionMonitor, but only when the test runner has accessibility permission and a user is logged in with an active window server session.

Two consequences follow. First, the test must run in a real logged-in macOS session, because there is no supported macOS-app simulator (Xcode's simulators target iOS, iPadOS, watchOS, tvOS and visionOS). Second, the monitor fires only when XCTest performs the next interaction on the host app, which is why a stray app.tap() after triggering the request is load-bearing in every working example.

How do I reset the permission state before each run?

Run tccutil reset before launching, because the dialog appears only while the status is .notDetermined. This needs administrator access to the Mac, which you have on your own Mac or VM.

#!/bin/bash
set -euo pipefail
BUNDLE_ID="${1:?Usage: $0 <bundle-id>}"
tccutil reset UserNotifications "$BUNDLE_ID" \
  || tccutil reset UserNotification "$BUNDLE_ID"
echo "Notification permission reset for $BUNDLE_ID"

The service name has varied between UserNotifications and UserNotification across macOS releases, and some releases route notification choices outside TCC entirely. Verify on your target OS by running the reset, relaunching the app and confirming the dialog reappears. If it does not, reinstall the app bundle or start from a clean image.

How do I handle the system alert in XCUITest?

Register the monitor, launch, tap your enable control, then call app.activate().

import XCTest

final class NotificationPermissionTests: XCTestCase {
    var app: XCUIApplication!

    override func setUp() {
        super.setUp()
        continueAfterFailure = false
        app = XCUIApplication()
    }

    func testGrantNotificationPermission() throws {
        addUIInterruptionMonitor(withDescription: "Notification Permission Dialog") { alert in
            let shot = alert.screenshot()
            let attachment = XCTAttachment(screenshot: shot)
            attachment.name = "notification-permission-dialog"
            attachment.lifetime = .keepAlways
            self.add(attachment)

            let allow = alert.buttons["Allow"]
            guard allow.exists else { return false }
            allow.tap()
            return true
        }

        app.launch()
        app.buttons["Enable Notifications"].tap()
        app.activate() // force the monitor to drain
        let status = waitForAuthStatus(expected: .authorized)
        XCTAssertEqual(status, .authorized)
    }
}

app.activate() (or any follow-up tap on the host app) is what makes XCTest evaluate the registered monitors. Without it, the handler can be skipped and the dialog times out as an implicit deny. Replace the example button identifier with your own project's control. For the deny path, tap alert.buttons["Don't Allow"] in the same monitor and assert .denied.

How do I assert UNAuthorizationStatus without sleeping?

Poll getNotificationSettings inside an expectation.

import UserNotifications
import XCTest

@discardableResult
func waitForAuthStatus(
    expected: UNAuthorizationStatus,
    timeout: TimeInterval = 8.0
) -> UNAuthorizationStatus {
    final class Box: @unchecked Sendable { var value: UNAuthorizationStatus = .notDetermined }
    let box = Box()
    let done = XCTestExpectation(description: "authStatus == \(expected)")

    func poll() {
        UNUserNotificationCenter.current().getNotificationSettings { s in
            box.value = s.authorizationStatus
            if s.authorizationStatus == expected {
                done.fulfill()
            } else {
                DispatchQueue.global().asyncAfter(deadline: .now() + 0.5, execute: poll)
            }
        }
    }
    poll()
    let result = XCTWaiter().wait(for: [done], timeout: timeout)
    XCTAssertEqual(result, .completed,
        "Expected \(expected), observed \(box.value) after \(timeout)s")
    return box.value
}

Polling every 0.5 s avoids sleep() on the test thread and surfaces a real failure message when the dialog was never dismissed.

How do I keep the screenshot as evidence?

Set the attachment lifetime explicitly. Attachments from passing tests are deleted by default, which quietly erases your QA evidence.

let shot = alert.screenshot()
let attachment = XCTAttachment(screenshot: shot)
attachment.name = "notification-permission-\(Int(Date().timeIntervalSince1970))"
attachment.lifetime = .keepAlways
self.add(attachment)

Everything lands in the .xcresult bundle and can be extracted with xcrun xcresulttool for your CI's artifact store. If the test fails, do not rerun the suite and count the next green run as the result. The failure is the signal.

Does every plan give the GUI session this notification test needs?

Any plan with remote desktop gives you the logged-in GUI session this test needs, and we have not run this test on any plan. The Intel Mac VM ($25 a month, $2 a day) runs macOS Sequoia with Xcode 26.3 or earlier and fits Intel or universal targets. It cannot run arm64-only binaries or Xcode 26.4 or later, so choose the Apple Silicon Mac VM ($39 a month, $6 a day) for those. Grant accessibility permission to the test runner in System Settings once per Mac. See the Mac hosting plans and check the macOS version shown before purchase.

Related guides

Which Figment Mac fits this work?

Intel Mac VM from $25 a month, Apple Silicon Mac VM from $39, or a Dedicated M4 Pro for $199. Hourly and daily plans too. You pay before use, starting with at least $25 of account credit.

Choose a Mac plan