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?
Asked
Active
Viewed 4,244 times
2 Answers
10
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/

Carlos Chaguendo
- 2,895
- 19
- 24
-
3This seems like the best answer given the fairly limited API options. Worth highlighting that you also need to add the "Communication Notifications" capability to your target in order to read the focus status (in addition to requesting authorization in the app itself). – Brian Sachetta Jan 21 '22 at 17:16
-
`INFocusStatusCenter.default.focusStatus.isFocused` its always return false. even when focus mode is enabled – Wahab Khan Jadon Oct 25 '22 at 13:40
1
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.

Cameron Pak
- 21
- 2