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

त्वरित शुरुआत

इस गाइड में AIBuds SDK iOS की बुनियादी सेटअप प्रक्रिया और आम तौर पर उपयोग होने वाले ऑपरेशन क्रमवार दिए गए हैं।

AI की सहायता से लागू करें

AI से बनाएँ

इस वर्कफ़्लो को AI से लागू करें

आधिकारिक “AIBuds SDK एकीकृत करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।

https://docs-aibuds.github.io/hi/skills/integrate-aibuds-sdk को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds SDK एकीकृत करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।
आधिकारिक स्किल देखें

चरण 1: SDK इंपोर्ट करें

जिन फ़ाइलों में SDK उपयोग किया गया है, उनमें आवश्यक मॉड्यूल इंपोर्ट करें:

Swift
import AIBuds
import ABMate
import AIBudsLog
import AIBudsAIFoundation
import AIBudsAI
import AIBudsStarBurst
import AIBudsMagicHelper
import AIBudsVoiceAssistant
import AIBudsXLFacility
import AIBudsLiveStream
import AIBudsCrashReporter
import AIBudsAllInOne

चरण 2: SDK इनिशियलाइज़ करें

ऐप शुरू होते समय AIBuds SDK को इनिशियलाइज़ करें। यह आम तौर पर AppDelegate या SceneDelegate में किया जाता है:

Swift
// AppDelegate.swift

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    // Initialize AIBuds SDK with Full Installation
    initWithFullInstallation()

    // Initialize AIBuds SDK with Custom Installation
    //initWithCustomInstallation()

    return true
}

/// Initialize AIBuds SDK with Full Installation
private func initWithFullInstallation() {
    // Initialize AIBuds SDK
    if !AllInOneSDK.init(withDelegate: self) {
        print("Failed to initialize AIBuds AllInOne SDK.")
    }

    // Install crash reporter
    AllInOneSDK.installCrashReporter { reportFilePath in
        print("Last crash report path: \(reportFilePath ?? "")")
    } reportListUpdateCallback: {
        print("Crash report list updated")
    }
    // Set user info for crash reporter
    CrashReporterSDK.setUserInfo("Tom", forKey: "User Name")
    CrashReporterSDK.setUserInfo("199", forKey: "User ID")

    // Start AI dashboard
    AllInOneSDK.startAIDashboard()
}

/// Initialize AIBuds SDK with Custom Installation
private func initWithCustomInstallation() {
    // Set XLFacility plugin
    AIBudsLogSDK.setXLFacilityPlugin(XLFacilitySDK.shared())

    // Initialize AIBuds SDK with all Ble SDKs you would like to integrate into your app
    let sdkConfiguration = SDKConfiguration.default()
    // Set log level to verbose
    sdkConfiguration.logLevel = .verbose
    let success = AIBudsSDK.initialize(
        [ABMateSDK.shared()],
        configuration: sdkConfiguration,
        delegate: self)
    if !success {
        print("AIBudsSDK initialize failed.")
    }

    // Install StarBurst AI plugin
    AIBudsSDK.setStarBurstAIPlugin(StarBurstAuthPlugin.shared())
    // Install MltCloud AI plugin
    AIBudsSDK.setMltCloudAIPlugin(MltCloudAuthPlugin.shared())

    // Install OnDeviceVoiceAssistant plugin
    AIBudsSDK.setOnDeviceVoiceAssistantPlugin(OnDeviceVoiceAssistantPlugin.shared())

    // Initialize AI SDK with all AI SDKs you would like to integrate into your app
    let aiSuccess = AIBudsAISDK.initialize([
        StarBurstSDK.shared(),
        MagicHelperSDK.shared(),
    ])
    if !aiSuccess {
        print("AIBudsAISDK initialize failed.")
    }

    // Install crash reporter
    CrashReporterSDK.installCrashReporter { reportFilePath in
        print("Last crash report path: \(reportFilePath ?? "")")
    } reportListUpdateCallback: {
        print("Crash report list updated")
    }
    // Set user info for crash reporter
    CrashReporterSDK.setUserInfo("Tom", forKey: "User Name")
    CrashReporterSDK.setUserInfo("199", forKey: "User ID")

    // Start AI dashboard
    AIDashboardSDK.start()
}

चरण 3: डिवाइस खोजें

उपलब्ध AIBuds डिवाइस खोजने के लिए स्कैन शुरू करें:

Swift
// Start scanning for devices
AIBudsSDK.startScanning(
    deviceFoundHandler: { device, isExistingDevice in
        print("Found device: \(device.name), RSSI: \(device.rssi)")
        print(isExistingDevice ? "Already stored" : "New device")
    },
    completion: {
        print("Scanning stopped")
    }
)

चरण 4: डिवाइस जोड़ें

खोजे गए डिवाइस को 'मेरे डिवाइस' में जोड़ने पर वह ऐप दोबारा खुलने के बाद भी उपलब्ध रहेगा। स्कैन से मिले FoundDeviceConvertible को makeStorableDeviceFromDiscovered(_:) से स्टोर किए जा सकने वाले रूप में बदलें, फिर StoredDevicesMgr से सहेजें:

Swift
func store(_ discoveredDevice: FoundDeviceConvertible) {
    // Convert the SDK scan result into a persistent device.
    guard let device = AIBudsSDK.makeStorableDeviceFromDiscovered(discoveredDevice) else {
        return
    }

    // Optional app-owned display information.
    device.screenName = device.name
    device.thumbnail = UIImage(named: "icon.glasses")
    device.customContent = "Smart Glasses"

    if StoredDevicesMgr.addDevice(device) {
        AIBudsSDK.stopScanning()
        navigationController?.popViewController(animated: true)
    }
}

चरण 5: डिवाइस से कनेक्ट करें

सहेजे गए डिवाइस से ConnectParams के माध्यम से कनेक्ट करें। AI प्रमाणीकरण पैरामीटर देने पर SDK कनेक्शन के दौरान चुनी गई AI सेवाओं का प्रमाणीकरण भी करता है:

Swift
let device = devices[indexPath.item]

let param = ConnectParams()
let aiAuthParams = AIAuthParams()

// StarBurst AI auth
let starBurstAuthParams = StarBurstAIAuthParams()
starBurstAuthParams.productId = configs["STARBURST_PRODUCTID"]
if let ppeEnv = configs["STARBURST_PPEENV"] as? String, !ppeEnv.isEmpty {
    starBurstAuthParams.ppeEnv = ppeEnv
}
aiAuthParams.starburst = starBurstAuthParams

// MltCloud AI auth
let mltCloudAuthParams = MltCloudAIAuthParams()
mltCloudAuthParams.channelId = configs["MLTCLOUD_CHANNELID"]
aiAuthParams.mltcloud = mltCloudAuthParams

param.aiAuthParams = aiAuthParams
param.userId = "199"

// Connect to the device
device.connect(param)

चरण 6: कमांड भेजें

कनेक्शन बनने के बाद डिवाइस को कमांड भेजे जा सकते हैं:

Swift
// Example: Set device time
guard let device = device as? DeviceInfoAPI else { return }
let date = Date()
device.setDeviceTime(date) { success, statusCode, error in
    if success {
        print("Device time set successfully")
    } else {
        print("Failed to set device time: \(error?.localizedDescription ?? "Unknown error")")
    }
}

चरण 7: डिवाइस डेलीगेट इवेंट संभालें

कनेक्शन लाइफ़साइकल इवेंट पाने के लिए DeviceDelegate प्रोटोकॉल अपनाएँ। सभी मेथड @objc optional हैं, इसलिए केवल आवश्यक callback लागू करें:

Swift
// Mark your class as the device's delegate
device.delegate = self

// Implement the optional delegate methods
extension YourViewController: DeviceDelegate {
    func didStartConnectingDevice(_ device: DeviceConvertible) {
        print("Connecting to \(device.name)…")
    }

    func didConnectedToDevice(_ device: DeviceConvertible) {
        print("Connected to \(device.name)")
    }

    func didFailToConnectDevice(_ device: DeviceConvertible?, error: NSError?) {
        print("Failed to connect: \(error?.localizedDescription ?? "Unknown error")")
    }

    func device(_ device: DeviceConvertible?, didDisconnectWithError error: NSError?) {
        if let error {
            print("Disconnected with error: \(error.localizedDescription)")
        } else {
            print("Disconnected")
        }
    }

    func deviceDidReady(_ device: DeviceConvertible) {
        print("Device ready: \(device.name)")
    }

    /// ... other delegate methods...
}

चरण 8: डिवाइस डिस्कनेक्ट करें

डिवाइस का उपयोग पूरा होने पर उसे डिस्कनेक्ट करें:

Swift
// Disconnect from a device
device.disconnect()

उदाहरण ऐप

वास्तविक ऐप में SDK के उपयोग का पूरा उदाहरण AIBudsSDK-Demo प्रोजेक्ट में उपलब्ध है।

आगे क्या करें

बुनियादी उपयोग समझने के बाद SDK की अन्य सुविधाएँ देखें: