Aygıt Dilini Ayarlama
Bağlı aygıtın kullanacağı dili ayarlayın. Hedef dil, SDK'nın DeviceLanguage enum'u ile temsil edilir.
Ön Koşullar
Aygıt dilini ayarlamadan önce şunları doğrulayın:
- Aygıt bağlı ve kararlı durumdadır
- Aygıt
DeviceInfoAPIprotokolünü destekler - Seçilen dil aygıtın
supportedLanguageslistesinde yer alır
API Reference
Framework
AIBuds.xcframework
Import
SDK'yı kullanacağınız dosyalarda ana framework'ü içe aktarın:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
setDeviceLanguage yöntemi DeviceInfoAPI içinde tanımlıdır. Bu protokol temel aygıt API protokolünden türetilir.
- 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;
@endÖrnek Yöntemi
Aygıt dilini desteklenen bir DeviceLanguage değerine ayarlar.
- 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;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
language | DeviceLanguage / AIBudsDeviceLanguage | Ayarlanacak hedef dil. |
completion | AIBudsCompletionHandler? | İşlem tamamlandığında çağrılan isteğe bağlı tamamlanma işleyicisi. |
Geri Çağrı Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | İşlem başarılıysa true; aksi halde false. |
error | NSError? | İşlem başarısızsa hata ayrıntıları; aksi halde nil. |
Dönüş Değeri
Bu yöntem doğrudan bir değer döndürmez. Sonuç tamamlanma işleyicisi aracılığıyla iletilir.
Kullanım Örnekleri
- 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");
}];
}
@endHata Yönetimi
- Yeni dili uygulanmış kabul etmeden önce
successdeğerini kontrol edin. - İşlem başarısız olduğunda hata ayrıntıları için
errordeğerini kullanın. - Komutu göndermeden önce desteklenmeyen değerleri reddedin.
- Hedef aygıt için belgelenmedikçe belirli bir hata kodu varsaymayın.
En İyi Uygulamalar
- SDK Enum'unu Kullanın: ISO dil kodu dizesi yerine bir
DeviceLanguagedeğeri verin. - Desteklenen Dilleri Denetleyin: Yöntemi çağırmadan önce enum'un ham değerini
supportedLanguagesile karşılaştırın. - Protokol Uyumluluğunu Denetleyin: Aygıtın
DeviceInfoAPIdesteğini doğrulayın. - Arayüzü Ana Kuyrukta Güncelleyin: Tamamlanma geri çağrısına bağlı UIKit güncellemelerini ana kuyruğa aktarın.
Notlar
supportedLanguages,NSNumberiçinde sarmalanmışDeviceLanguageham değerlerini içerir.languageSetting, aygıtın geçerli dil ayarını sunar.- Desteklenen diller aygıt modeline ve firmware sürümüne göre değişebilir.
- SDK Demo'su dili
AIBudsDeviceLanguageEnglisholarak ayarlar; üretim uygulamaları aygıtın bildirdiği değerler arasından seçim yapmalıdır.