मुख्य कंटेंट तक स्किप करें

डिवाइस की भाषा सेट करें

जुड़े डिवाइस की भाषा सेट करें। लक्ष्य भाषा SDK के DeviceLanguage enum से दर्शाई जाती है।

पहले की आवश्यकताएँ

डिवाइस की भाषा set करने से पहले सुनिश्चित करें:

  • डिवाइस connected और stable state में है
  • डिवाइस DeviceInfoAPI protocol का समर्थन करता है
  • चुनी गई भाषा डिवाइस की supportedLanguages list में है

API संदर्भ

फ्रेमवर्क

AIBuds.xcframework

Import

SDK उपयोग करने वाली files में main framework import करें:

Swift
import AIBuds

प्रोटोकॉल

setDeviceLanguage method DeviceInfoAPI में परिभाषित है। यह protocol base device API protocol से inherit करता है।

Swift
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?
    )
}

Instance method

डिवाइस की भाषा को समर्थित DeviceLanguage value पर set करता है।

Swift
/// 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?
)

पैरामीटर

पैरामीटरप्रकारविवरण
languageDeviceLanguage / AIBudsDeviceLanguageSet की जाने वाली लक्ष्य भाषा।
completionAIBudsCompletionHandler?Operation पूरा होने पर call होने वाला optional completion handler।

Callback पैरामीटर:

नामप्रकारविवरण
successBool / BOOLOperation सफल हो तो true, अन्यथा false
errorNSError?Operation असफल हो तो error details, अन्यथा nil

Return value

यह method सीधे कोई value return नहीं करता। परिणाम completion handler से मिलता है।

उपयोग के उदाहरण

Swift
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")
        }
    }
}

Error handling

  1. नई भाषा लागू मानने से पहले success जाँचें।
  2. Operation असफल होने पर details के लिए error उपयोग करें।
  3. Command भेजने से पहले unsupported values रोकें।
  4. लक्ष्य डिवाइस के लिए documented न होने वाला error code न मानें।

बेहतर तरीके

  1. SDK enum उपयोग करें: ISO language-code string के बजाय DeviceLanguage value दें।
  2. Supported languages जाँचें: Method call करने से पहले enum raw value की supportedLanguages से तुलना करें।
  3. Protocol conformance जाँचें: DeviceInfoAPI support की पुष्टि करें।
  4. UI main queue पर अपडेट करें: Completion से आने वाले UIKit updates main queue पर भेजें।

ध्यान देने योग्य बातें

  • supportedLanguages में NSNumber values होती हैं, जिनमें DeviceLanguage raw values रहती हैं।
  • languageSetting डिवाइस की मौजूदा भाषा देता है।
  • Supported languages model और firmware के अनुसार बदल सकती हैं।
  • SDK Demo भाषा AIBudsDeviceLanguageEnglish पर set करता है; production app को डिवाइस द्वारा बताई values में से चुनना चाहिए।