4

How to find the current focus status inside the app?

I implemented SetFocusFilterIntent for focus filter API. Is it possible to detect the current focus mode inside our main app?

Divagar.G
  • 41
  • 4

2 Answers2

1

Yes, it is possible to get the current configuration by accessing the static current variable of your intent.

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension SetFocusFilterIntent {

    public static var current: Self { get async throws }
}
siburb
  • 4,880
  • 1
  • 25
  • 34
0

If you need to initialise the appropriate handling of Focus Filters on startup of your app, you can use the following code in applicationDidFinishLaunching or another event handler:

Task {
   let filterIntent = try await SetFocusFilterIntent.current
   _ = try await filterIntent.perform()
}
Ely
  • 8,259
  • 1
  • 54
  • 67