डिवाइस की भाषा सेट करें
जुड़े डिवाइस की भाषा सेट करें। लक्ष्य भाषा SDK के DeviceLanguage enum से दर्शाई जाती है।
पहले की आवश्यकताएँ
डिवाइस की भाषा set करने से पहले सुनिश्चित करें:
- डिवाइस connected और stable state में है
- डिवाइस
DeviceInfoAPIprotocol का समर्थन करता है - चुनी गई भाषा डिवाइस की
supportedLanguageslist में है
API संदर्भ
फ्रेमवर्क
AIBuds.xcframework
Import
SDK उपयोग करने वाली files में main framework import करें:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
setDeviceLanguage method DeviceInfoAPI में परिभाषित है। यह protocol base device API protocol से inherit करता है।
- Swift
- Objective-C
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;
@endInstance method
डिवाइस की भाषा को समर्थित DeviceLanguage value पर set करता है।
- Swift
- Objective-C
/// 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;पैरामीटर
| पैरामीटर | प्रकार | विवरण |
|---|---|---|
language | DeviceLanguage / AIBudsDeviceLanguage | Set की जाने वाली लक्ष्य भाषा। |
completion | AIBudsCompletionHandler? | Operation पूरा होने पर call होने वाला optional completion handler। |
Callback पैरामीटर:
| नाम | प्रकार | विवरण |
|---|---|---|
success | Bool / BOOL | Operation सफल हो तो true, अन्यथा false। |
error | NSError? | Operation असफल हो तो error details, अन्यथा nil। |
Return value
यह method सीधे कोई value return नहीं करता। परिणाम completion handler से मिलता है।
उपयोग के उदाहरण
- Swift
- Objective-C
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");
}];
}
@endError handling
- नई भाषा लागू मानने से पहले
successजाँचें। - Operation असफल होने पर details के लिए
errorउपयोग करें। - Command भेजने से पहले unsupported values रोकें।
- लक्ष्य डिवाइस के लिए documented न होने वाला error code न मानें।
बेहतर तरीके
- SDK enum उपयोग करें: ISO language-code string के बजाय
DeviceLanguagevalue दें। - Supported languages जाँचें: Method call करने से पहले enum raw value की
supportedLanguagesसे तुलना करें। - Protocol conformance जाँचें:
DeviceInfoAPIsupport की पुष्टि करें। - UI main queue पर अपडेट करें: Completion से आने वाले UIKit updates main queue पर भेजें।
ध्यान देने योग्य बातें
supportedLanguagesमेंNSNumbervalues होती हैं, जिनमेंDeviceLanguageraw values रहती हैं।languageSettingडिवाइस की मौजूदा भाषा देता है।- Supported languages model और firmware के अनुसार बदल सकती हैं।
- SDK Demo भाषा
AIBudsDeviceLanguageEnglishपर set करता है; production app को डिवाइस द्वारा बताई values में से चुनना चाहिए।