In SOTU, a Focus Status API was announced for communication apps, but I haven't found any session nor documentation about it. Where can I find more information about that new API?
Where is the Focus Status API
More information can be found in https://developer.apple.com/documentation/sirikit/messaging
Section: Sharing the User’s Focus Status
Highlights:
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
INShareFocusStatusIntent (launches Intent Extension whenever Focus is enabled or disabled)
extension IntentHandler: INShareFocusStatusIntentHandling {
func handle(intent: INShareFocusStatusIntent, completion: @escaping (INShareFocusStatusIntentResponse) -> Void) {
/// Check if Focus is enabled.
if intent.focusStatus?.isFocused == true {
/// Focus is enabled
}
/// Provide a response
let response = INShareFocusStatusIntentResponse(code: .success, userActivity: nil)
completion(response)
}
}
Will this only be available in communications apps? I have a use case in a media app I am working on, to sync with or read the users focus status to change what is displayed
Yes, Focus Status will only be available to apps that have the Communication Notifications capability added in Xcode's Signing & Capabilities tab, which also adds the Communication Notification boolean YES to the target's .entitlements file.
The IntentHandler in the Intents Extension is never called when changing my Focus Status.
I have done all the setup. Extension is called for messaging based intents just not for focus ones.
When running the Intents target, selecting my app (or siri): func handler(for intent: INIntent) is never called.
I have scoured the internet for several days. Please help.
Is there a corresponding API for macOS, or only for mobile and Catalyst apps? The setting appears to exist on Mac, but I don't see any documentation on how to make use of it.
Is there any easy way to observe the focus status during runtime? Observing INFocusStatusCenter.default.focusStatus
via KVO doesn't seem to work for me. Should this work? I cannot observe INFocusStatusCenter.default.focusStatus.isFocused
directly as it's a non-'@objc dynamic' property. The only way for me to get focus status updates right now is to poll it frequently as I also cannot get the intent handling to work.