Where is the Focus Status API

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?

Replies

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.

  • Is it enough to add the Communications Notification capability in Xcode to use this or does one need to donate actual message or call intents? Our app for medical providers could use access to the Focus Status, we believe, but our model does not lend itself well, at this time, to actually donating the intents and using Communications Notifications. We are still working through what it all means. Thanks.

Add a Comment

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.

  • Also this is literally the only documentation on the internet about this API. Please fix.

  • For the INShareFocusStatusIntent to work, the following requirements must be met in the app where the Intent Extension is embedded:

    UserNotifications allowed.Communication Notifications capability added via Target > Signing & Capabilities > + Capability
  • Same for me, can't get it to work.

Add a Comment

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.

  • To observe Focus Status changes as they happen, please implement an Intents extension and handle incoming INShareFocusStatusIntent with INShareFocusStatusIntentHandling.

    One option to observe this change is to share the focus status from the extension via App Groups and UserDefaults(suiteName:_) then KVO that user defaults suite and key from the parent app.

Add a Comment