-
Notifications
You must be signed in to change notification settings - Fork 0
Core Device Info Set Language
Mr.P edited this page Aug 29, 2026
·
2 revisions
Set the language used by a connected device. The target language is represented by the SDK's DeviceLanguage enum.
Before setting the device language, ensure:
- The device is connected and in a stable state
- The device supports the
DeviceInfoAPIprotocol - The selected language appears in the device's
supportedLanguageslist
AIBuds.xcframework
In the files where you want to use the SDK, import the main framework:
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>The setDeviceLanguage method is defined in DeviceInfoAPI. The protocol inherits from the base device API protocol.
protocol DeviceInfoAPI: DeviceAPI {
/// Current language setting of the device.
var languageSetting: DeviceLanguage { get }
/// List of languages supported by the device, each element is an
/// `NSNumber` wrapping the raw value of `DeviceLanguage`.
var supportedLanguages: [NSNumber] { get }
/// Sets the device language.
/// - Parameters:
/// - language: The target language to set.
/// - 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 setDeviceLanguage(
_ language: DeviceLanguage,
completion: AIBudsCompletionHandler?
)
}@protocol AIBudsDeviceInfoAPI <AIBudsDeviceAPI>
/// Current language setting of the device.
@property(nonatomic, readonly) enum AIBudsDeviceLanguage languageSetting;
/// List of languages supported by the device, each element is an
/// `NSNumber` wrapping the raw value of `DeviceLanguage`.
@property(nonatomic, readonly, copy) NSArray<NSNumber *> *_Nonnull supportedLanguages;
/// Sets the device language.
/// - Parameters:
/// - language: The target language to set.
/// - 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.
- (void)setDeviceLanguage:(enum AIBudsDeviceLanguage)language
completion:(AIBudsCompletionHandler _Nullable)completion;
@endSets the device language to a supported DeviceLanguage value.
/// Sets the device language.
/// - Parameters:
/// - language: The target language to set.
/// - 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 setDeviceLanguage(
_ language: DeviceLanguage,
completion: AIBudsCompletionHandler?
)/// Sets the device language.
/// - Parameters:
/// - language: The target language to set.
/// - 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.
- (void)setDeviceLanguage:(enum AIBudsDeviceLanguage)language
completion:(AIBudsCompletionHandler _Nullable)completion;| Parameter | Type | Description |
|---|---|---|
language |
DeviceLanguage / AIBudsDeviceLanguage
|
The target language to set. |
completion |
AIBudsCompletionHandler? |
Optional completion handler called when the operation finishes. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
success |
Bool / BOOL
|
true if the operation succeeded; otherwise false. |
error |
NSError? |
Error details if the operation failed; otherwise nil. |
This method does not return a value directly. The result is provided through the completion handler.
import AIBuds
final class DeviceManager {
weak var device: DeviceConvertible?
func setDeviceLanguage(_ language: DeviceLanguage) {
guard let device = device as? DeviceInfoAPI else {
print("Device does not support language settings")
return
}
let isSupported = device.supportedLanguages.contains {
$0.intValue == language.rawValue
}
guard isSupported else {
print("The selected language is not supported by this device")
return
}
device.setDeviceLanguage(language) { success, error in
if !success {
print("Failed to set language: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("Device language set successfully")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)setDeviceLanguage:(AIBudsDeviceLanguage)language {
id<AIBudsDeviceInfoAPI> device = (id<AIBudsDeviceInfoAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceInfoAPI)]) {
NSLog(@"Device does not support language settings");
return;
}
if (![device.supportedLanguages containsObject:@(language)]) {
NSLog(@"The selected language is not supported by this device");
return;
}
[device setDeviceLanguage:language
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to set language: %@",
error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Device language set successfully");
}];
}
@end- Check
successbefore treating the new language as applied. - Use
errorfor failure details when the operation does not succeed. - Reject unsupported values before sending the command.
- Do not assume a specific error code unless it is documented for the target device.
-
Use the SDK Enum: Pass a
DeviceLanguagevalue instead of an ISO language-code string. -
Check Supported Languages: Compare the enum's raw value with
supportedLanguagesbefore calling the method. -
Check Protocol Conformance: Confirm that the device supports
DeviceInfoAPI. - Update UI on the Main Queue: Dispatch completion-driven UIKit updates to the main queue.
-
supportedLanguagescontainsNSNumbervalues that wrapDeviceLanguageraw values. -
languageSettingexposes the device's current language setting. - Supported languages can vary by device model and firmware.
- The SDK Demo sets the language to
AIBudsDeviceLanguageEnglish; production applications should select from the device's advertised values.
AIBuds SDK documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting