sirikit について
sirikitは、SiriKit対応を実装するAppleアプリ開発者向けの開発スキルです。カスタムインテントやショートカット、提案機能の処理パターンと設定を扱います。
主な機能
- 01Intents拡張機能とSiriアクセスの設定
- 02カスタムインテントとパラメーターの定義
- 03インテントの解決・確認・実行処理
- 04ショートカットの提供と削除
- 05Siri UIとボキャブラリーのカスタマイズ
活用シーン
- 01アプリに音声操作を追加
- 02ユーザー操作に応じたショートカットの提案
- 03アプリでSiriインテントを受信して処理
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ ios-agent/ iosagent.dev --skill sirikitインストール後、Claude Code で/sirikitを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/app-intents.mdcustom-intents.mdintent-handling.mdintents-ui.mdshortcuts.mdvocabulary.md詳細
SiriKit 開発スキル
音声、ショートカット、インテリジェントな提案を通じて、ユーザーがアプリを操作できるようにします。
クイックスタート
インテント拡張機能を追加する
- ファイル → 新規 → ターゲット → インテント拡張機能
- Siri のインターフェースをカスタマイズする場合は、「UI 拡張機能を含める」を有効にします
- メインアプリのターゲットで Siri ケイパビリティを有効にします(署名とケイパビリティ)
最小限のインテントハンドラー
import Intents
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
switch intent {
case is OrderSoupIntent:
return OrderSoupIntentHandler()
default:
return self
}
}
}
class OrderSoupIntentHandler: NSObject, OrderSoupIntentHandling {
// 1. Resolve parameters
func resolveSoup(for intent: OrderSoupIntent) async -> SoupResolutionResult {
guard let soup = intent.soup else {
return .needsValue()
}
return .success(with: soup)
}
// 2. Confirm intent
func confirm(intent: OrderSoupIntent) async -> OrderSoupIntentResponse {
return OrderSoupIntentResponse(code: .ready, userActivity: nil)
}
// 3. Handle intent
func handle(intent: OrderSoupIntent) async -> OrderSoupIntentResponse {
// Fulfill the request
return OrderSoupIntentResponse.success(message: "Your order is confirmed!")
}
}
インテント処理フロー
┌─────────────────────────────────────────────────────────────┐
│ User speaks to Siri │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 1. RESOLVE - Validate each parameter │
│ • Return .success(with:) if valid │
│ • Return .needsValue() if missing │
│ • Return .disambiguation(with:) for choices │
│ • Return .unsupported() if invalid │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 2. CONFIRM - Final validation before execution │
│ • Verify services are ready │
│ • Return .ready or appropriate failure code │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ 3. HANDLE - Fulfill the intent │
│ • Execute the action │
│ • Return success/failure response │
└─────────────────────────────────────────────────────────────┘
システムインテントのドメイン
| ドメイン | ユースケース | 主なインテント |
|---|---|---|
| メッセージ | メッセージの送信・検索 | INSendMessageIntent、INSearchForMessagesIntent |
| 通話 | VoIP 通話 | INStartCallIntent、INSearchCallHistoryIntent |
| 支払い | 送金 | INSendPaymentIntent、INRequestPaymentIntent |
| 配車予約 | 配車のリクエスト | INRequestRideIntent、INGetRideStatusIntent |
| ワークアウト | ワークアウトの開始・終了 | INStartWorkoutIntent、INEndWorkoutIntent |
| メディア | オーディオ・ビデオの再生 | INPlayMediaIntent、INAddMediaIntent |
| 写真 | 写真の検索 | INSearchForPhotosIntent |
| リストとメモ | メモ・タスクの作成 | INCreateNoteIntent、INAddTasksIntent |
| 車のコマンド | 車両の操作 | INSetCarLockStatusIntent、INActivateCarSignalIntent |
| 予約 | レストランの予約 | INGetReservationDetailsIntent |
カスタムインテント
インテント定義ファイルで定義する
Intents.intentdefinitionファイルを作成します- 動詞+名詞の命名規則で新しいインテントを追加します(例:
OrderSoup) - 用途に合ったカテゴリを設定します
- 型を指定してパラメーターを定義します
パラメーターの型
- システム:String、Integer、Boolean、Date、Person、Location、Currency
- カスタム:列挙型またはオブジェクトとして独自の型を定義します
リファレンスドキュメント
- インテント処理:解決、確認、処理のパターン
- ショートカット:ショートカットの提供、提案、管理
- カスタムインテント:インテント定義ファイル、パラメーター、応答
- IntentsUI:カスタム Siri インターフェースのビュー
- 語彙:カスタムの用語とフレーズ
- App Intents への移行:最新の App Intents フレームワーク
主な設定
Info.plist(インテント拡張機能)
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>IntentsSupported</key>
<array>
<string>OrderSoupIntent</string>
</array>
<key>IntentsRestrictedWhileLocked</key>
<array>
<string>INSendPaymentIntent</string>
</array>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.intents-service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).IntentHandler</string>
</dict>
Siri の使用許可をリクエストする
import Intents
INPreferences.requestSiriAuthorization { status in
switch status {
case .authorized: print("Siri authorized")
case .denied: print("Siri denied")
case .notDetermined: print("Not determined")
case .restricted: print("Restricted")
@unknown default: break
}
}
よくあるパターン
ユーザー操作後にショートカットを提供する
import Intents
func donateOrderShortcut(order: Order) {
let intent = OrderSoupIntent()
intent.soup = order.soup
intent.quantity = order.quantity
let interaction = INInteraction(intent: intent, response: nil)
interaction.identifier = order.id.uuidString
interaction.donate { error in
if let error = error {
print("Donation failed: \(error)")
}
}
}
提供済みのショートカットを削除する
// Delete specific
INInteraction.delete(with: [orderID.uuidString]) { error in }
// Delete all from app
INInteraction.deleteAll { error in }
アプリ内でインテントを処理する(起動時)
// SwiftUI
.onContinueUserActivity(NSStringFromClass(OrderSoupIntent.self)) { activity in
if let intent = activity.interaction?.intent as? OrderSoupIntent {
handleOrderIntent(intent)
}
}
// UIKit SceneDelegate
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let intent = userActivity.interaction?.intent as? OrderSoupIntent {
handleOrderIntent(intent)
}
}
主な制約
- バックグラウンド実行:拡張機能が実行される時間は短いため、長時間のタスクではアプリを起動します
- 共有データ:アプリと拡張機能間のデータには App Groups を使用します
- 拡張機能内の UI は不可:カスタムビューには IntentsUI 拡張機能を使用します
- テスト:Siri が新しいインテントを認識するまで、インストール後しばらく待ちます
- ローカライズ:ローカライズされた
AppIntentVocabulary.plistを用意します
コメント
Markdown 対応