独自 AI サービスの認証結果を通知
reportSelfAiServiceAuthResult はデバイス側フローを同期するための通知であり、認証 API ではありません。アプリが独自の AI サービスを組み込む場合は、そのサービスをアプリ側で認証してから、結果を接続中のデバイスへ通知します。
デバイスは、独自 AI サービスの認証成功が通知されるまで、対象の AI 処理を継続しません。通知しないと、ホスト側サービスの準備ができていてもデバイス側の AI 経路はブロックされたままとなり、たとえばセッションに必要な Opus 音声ストリームが開始されない場合があります。
この API が必要な場合
ホストアプリが組み込みと認証を担当する AI サービスで、この API を使用します。ホスト側の認証処理が完了したら、次のように通知します。
- 独自 AI サービスが利用可能になった後にだけ
trueを通知します。 - 認証に失敗した場合やサービスを利用できない場合は
falseを通知します。 - 完了ハンドラーが成功してから、結果がデバイスへ届いたものとして扱います。
SDK が提供する AI サービスの認証には専用の導入フローがあります。この API をサービスプロバイダー認証の代わりに使用する必要はありません。
API Reference
- Swift
- Objective-C
/// Reports the authentication result for the self-AI service.
/// - Parameters:
/// - isAuthenticated: Whether the self-AI service is authenticated.
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func reportSelfAiServiceAuthResult(
_ isAuthenticated: Bool,
completion: AIBudsCompletionHandler?
)/// Reports the authentication result for the self-AI service.
- (void)reportSelfAiServiceAuthResult:(BOOL)isAuthenticated
completion:(AIBudsCompletionHandler _Nullable)completion;reportSelfAiServiceAuthResult を参照してください。
使用例
- Swift
- Objective-C
func selfAIAuthenticationDidFinish(isAuthenticated: Bool) {
guard let device = device as? DeviceServiceAuthAPI else { return }
// Report the result only after the host app's own AI authorization finishes.
device.reportSelfAiServiceAuthResult(isAuthenticated) { reportSucceeded, error in
guard reportSucceeded else {
print(error?.localizedDescription ?? "Failed to report authorization")
return
}
if isAuthenticated {
// The device can now continue eligible AI flows, including an Opus input stream.
print("Self-AI authorization delivered to the device")
}
}
}- (void)selfAIAuthenticationDidFinish:(BOOL)isAuthenticated {
id<AIBudsDeviceServiceAuthAPI> device = (id<AIBudsDeviceServiceAuthAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceServiceAuthAPI)])
return;
// Report the result only after the host app's own AI authorization finishes.
[device reportSelfAiServiceAuthResult:isAuthenticated
completion:^(BOOL reportSucceeded, NSError *error) {
if (!reportSucceeded) {
NSLog(@"%@", error.localizedDescription);
return;
}
if (isAuthenticated) {
// The device can now continue eligible AI flows, including
// an Opus input stream.
NSLog(@"Self-AI authorization delivered to the device");
}
}];
}完了ハンドラーは、結果がデバイスへ通知されたかどうかを示します。AI サービスを認証するものではありません。この API が受け付けるのは真偽値の結果だけです。アクセストークンや認証情報を送信しないでください。