패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.2.0

intelligence

Apple의 AppIntent 통합 플러그인. 앱이 Siri, 단축어 앱, Apple Intelligence 등에 의해 이해될 수 있도록 합니다.

iOS
30일 다운로드
1.1만
좋아요
51
Pub 점수
140

패키지 설치

flutter pub add intelligence

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

지능 패키지는 iOS 앱이 Apple의 AppIntents 프레임워크와 통합될 수 있도록 해주는 Flutter 플러그인으로, Siri, 단축어 앱 및 Apple 인텔리전스와 더 깊이 있는 상호작용을 가능하게 합니다. 사용자는 음성 명령이나 단축어를 통해 앱 작업을 트리거할 수 있어 접근성과 자동화가 향상됩니다. 이 플러그인은 의도, 매개변수 및 결과를 정의하기 위한 Dart 수준의 API를 제공함으로써 앱 기능을 Apple 생태계에 노출하는 과정을 간소화합니다. 이는 iOS 전용이며 Apple의 AppIntents 가이드라인 준수를 요구합니다.

사용 사례

  • 앱 작업용 Siri 음성 명령 사용 활성화
  • 쇼트컷 앱과 통합
  • Apple Intelligence 기능 지원
  • 사용자가 작업을 자동화할 수 있도록 허용
  • 애플 생태계에서 앱 탐색성 향상

주요 기능

  • Apple AppIntents와의 원활한 통합
  • 의도를 정의하기 위한 Dart API
  • Siri 및 단축키 지원
  • iOS 전용 플랫폼 호환성
  • Flutter pub add로 간편 설정

적합한 대상

  • Apple Intelligence를 대상으로 하는 iOS 개발자
  • 음성 명령 지원이 필요한 앱
  • 자동화 중심 애플리케이션
  • iOS에서 Flutter를 사용하는 개발자
  • 더 깊은 Siri 통합을 목표로 하는 앱

고려 사항

  • iOS 17 이상 필요
  • 애플 생태계에 제한됨
  • Xcode에서 AppIntents 구성이 필요합니다
  • Android와 호환되지 않습니다
  • Apple의 발전하는 AppIntents 프레임워크에 따라 다름

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Intelligence

MIT license PRs Welcome Monterail's logo

Add support for Apple's AppIntents framework to your Flutter application. For details on how to add integration with Siri, Shortcuts app, and Apple Intelligence, see Recipes.

Installation

Copy and paste the following snippet into your shell when in the target project directory.

dart pub add intelligence

Usage

To add support for AppIntents framework, you will have to perform one-time setup which differs for different use-cases. See Recipes for more details.

iOS Configuration

After installing the package, you need to set the minimum iOS version to 16.0 on XCode.

For more details, follow these steps:

  • Open the iOS project in Xcode

    Open in Xcode
  • Click on Runner & then general tab

    Runner & general tab

  • Under the General tab & minimum deployments section, set the iOS version to atleast 16.0 iOS version


Once set up, the plugin will let you act on each App Intent trigger.

E.g. while setting the selection listener in a Stateful widget:

Intelligence().selectionsStream().listen(_handleSelection);

Note: the Intelligence class behaves like a singleton, so you do not have to maintain the same class instance throughout the app/use-case.

Recipes

List of practical applications of intelligence in your project. Click the Details dropdown to see the implementation.

Allow the Shortcuts app to open a specific page in your application

Will let your app to be automated via Shortcuts workflow.

  • Open the iOS project in Xcode
Open in Xcode
  • Add a new Swift file and paste:
import AppIntents
import intelligence

struct OpenHeartIntent: AppIntent {
  static var title: LocalizedStringResource = "Draw a Heart"
  static var openAppWhenRun: Bool = true
  
  @MainActor
  func perform() async throws -> some IntentResult {
    IntelligencePlugin.notifier.push("heart")
    return .result()
  }
}

Switch out the struct's name, title, and the .pushed value to ones that match your use-case.

Once added, your App Intent will show up in the Shortcuts app:

Example of a Shortcuts app workflow including an automation step declared in this guide
Optionally: Add a Siri voice shortcut to for the App Intent

To trigger the App Intent declared above by speaking a specific phrase to Siri, append:

struct OpenHeartShortcuts: AppShortcutsProvider {
  static var appShortcuts: [AppShortcut] {
    AppShortcut(
      intent: ExampleAppIntent(),
      phrases: [
        "Draw my favorite shape in \(.applicationName)"
      ]
    )
  }
}

Once deployed to the device, Siri can understand the trigger phrase and run the App Intent declared above:

Siri's response to a query 'What can Intelligence do?' including defined phrase to run the App Intent declared in this guide
Let Siri open a specific entity from your app domain

Siri is capable of understanding the entities your application revolves around, letting you implement App Intents with variables.

See full implementation in the example project.

  • Define an AppEntity. It should contain a unique identifier and a text representation fields, as follows:
import CoreSpotlight
import AppIntents

struct RepresentableEntity: AppEntity {
  static var defaultQuery: RepresentableQuery = RepresentableQuery()
  static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Shape")
  
  var displayRepresentation: DisplayRepresentation {
    DisplayRepresentation(stringLiteral: representation)
  }
  
  let id: String
  let representation: String
}

extension RepresentableEntity: IndexedEntity {
  var attributeSet: CSSearchableItemAttributeSet {
    let attributes = CSSearchableItemAttributeSet()
    attributes.displayName = self.representation
    return attributes
  }
}
  • Create a matching EntityQuery, like so:
import AppIntents
import intelligence

struct RepresentableQuery: EntityQuery {
  func entities(for identifiers: [String]) async throws -> [RepresentableEntity] {
    return IntelligencePlugin.storage.get(for: identifiers).map() { item in
      return RepresentableEntity(
        id: item.id,
        representation: item.representation
      )
    }
  }
  
  func suggestedEntities() async throws -> [RepresentableEntity] {
    return IntelligencePlugin.storage.get().map() { item in
      return RepresentableEntity(
        id: item.id,
        representation: item.representation
      )
    }
  }
}

extension RepresentableQuery: EnumerableEntityQuery {
  func allEntities() async throws -> [RepresentableEntity] {
    return IntelligencePlugin.storage.get().map() { item in
      return RepresentableEntity(
        id: item.id,
        representation: item.representation
      )
    }
  }
}
  • Create an AppIntent using the entity as a parameter.
import AppIntents
import intelligence

struct ExampleAppIntent: AppIntent {
  static var title: LocalizedStringResource = "Draw shape"
  static var openAppWhenRun: Bool = true
    
  @Parameter(title: "Shape")
  var target: RepresentableEntity
  
  @MainActor
  func perform() async throws -> some IntentResult {
    IntelligencePlugin.notifier.push(target.id)
    return .result()
  }
  
  static var parameterSummary: some ParameterSummary {
    Summary("Draw \(\.$target)")
  }
}


struct AppShortcuts: AppShortcutsProvider {
  static var appShortcuts: [AppShortcut] {
    AppShortcut(
      intent: ExampleAppIntent(),
      phrases: [
        "Draw a \(\.$target) in \(.applicationName)"
      ]
    )
  }
}

  • In your AppDelegate file, add the following code to the didFinishLaunchingWithOptions method:
  IntelligencePlugin.storage.attachListener {
    AppShortcuts.updateAppShortcutParameters()
  }
  if #available(iOS 18.0, *) {
    IntelligencePlugin.spotlightCore.attachEntityMapper() { item in
      return RepresentableEntity(
        id: item.id,
        representation: item.representation
      )
    }
  }
  • In your Dart code, use the .populate method to let the operating system know about the entities available in your app:
await IntelligencePlugin().populate(const [
  Representable(representation: 'Heart', id: 'heart'),
  Representable(representation: 'Circle', id: 'circle'),
  Representable(representation: 'Rectangle', id: 'rectangle'),
  Representable(representation: 'Triangle', id: 'triangle'),
]);

Note: each call to .populate overwrites previous entities. Call .populate([]) once the entities are not accessible anymore, e.g. after a logout.

Result:

Siri query usage example

Further reading

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트