Результат авторизации собственного AI
reportSelfAiServiceAuthResult — сигнал синхронизации процесса устройства, а не API аутентификации. При интеграции собственного AI-сервиса приложение авторизует его самостоятельно, затем сообщает результат подключённому устройству.
Устройство ждёт успешный результат авторизации собственного AI перед продолжением доступных AI-сценариев. Без него сервис приложения уже может быть готов, но устройство по-прежнему блокирует AI-процесс — например, не запускает требуемый сеансом поток Opus.
Когда нужен этот API
Используйте API для AI-сервиса, интегрированного и авторизованного приложением. После завершения авторизации:
- Передавайте
trueтолько когда собственный AI-сервис готов к работе. - Передавайте
false, если авторизация не удалась или сервис недоступен. - Считайте результат доставленным на устройство только после успешного завершения обработчика.
Авторизация AI-сервисов, предоставляемых SDK, выполняется по собственному процессу интеграции; приложение не должно подменять её этим API.
Справочник API
- 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 токены или учётные данные: он принимает только логический результат.