What's the API for querying Focus mode on iOS 15?

Viewed 2458

iOS 15 introduced Focus mode. Apple mentioned that communication apps can query if the device is currently in Focus so we can tell the other person that they might not be notified of messages. However I couldn't find the API in apple docs. Does anyone know?

2 Answers

See https://developer.apple.com/forums/thread/682143

FocusStatusCenter

import Intents

/// Retrieve the current authorization status: INFocusStatusAuthorizationStatus
INFocusStatusCenter.default.authorizationStatus

/// Request authorization to check Focus Status
//
INFocusStatusCenter.default.requestAuthorization { status in
    /// Provides a INFocusStatusAuthorizationStatus
}

/// Check if Focus is enabled. INFocusStatusAuthorizationStatus must be .authorized
INFocusStatusCenter.default.focusStatus.isFocused

You need add NSFocusStatusUsageDescription to Info.plist

https://onesignal.com/blog/ios-notification-changes-updates-from-apples-wwdc-21/

I think this may help: https://developer.apple.com/documentation/sirikit/infocusstatus.

Apple states on their iOS 15 Developer Site the following, "With Focus, users can have notifications delivered at times that work best for them and with the Interruption Levels API, you can provide more nuanced delivery with one of four interruption levels (including new Passive and Time-Sensitive levels)." (source: apple.com)

If the above link doesn't help, perhaps the quote above will help.

Related