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

लॉग एक्सपोर्ट करें

Retained file या XLFacility logs export करें और app से बनी file URLs share करें।

आवश्यक शर्तें

  • Active destination .file या .xlfacility है।
  • .xlfacility चुनने पर XLFacility plugin installed है।
  • कम से कम एक retained log उपलब्ध है।

API संदर्भ

Framework

AIBudsLog.xcframework

डिक्लेरेशन

Swift
/// Exports all retained logs to one file.
/// - Parameter completion: Called with the exported path, optional beginning
///   and ending timestamps, and an error.
func exportLogs(_ completion: ((
                    _ filePath: String?,
                    _ logStartFrom: Date?,
                    _ logEndAt: Date?,
                    _ error: NSError?
                ) -> Void)?)

/// Exports retained logs to size-limited files.
/// - Parameters:
///   - maxFileSize: Maximum size of each exported file, in bytes.
///   - completion: Called with exported paths, optional beginning and ending
///     timestamps, and an error.
func exportLogs(_ maxFileSize: UInt64,
                   completion: ((
                       _ filePaths: [String]?,
                       _ logStartFrom: Date?,
                       _ logEndAt: Date?,
                       _ error: NSError?
                   ) -> Void)?)

दोनों operations LogService में परिभाषित हैं और logService पर call किए जाते हैं।

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

एक फ़ाइल एक्सपोर्ट करें

Swift
AIBudsLogSDK.logService.exportLogs { filePath, startDate, endDate, error in
    DispatchQueue.main.async {
        if let error {
            print("Export failed: \(error.localizedDescription)")
            return
        }

        guard let filePath else {
            print("Export completed without a file")
            return
        }

        print("Log range: \(String(describing: startDate)) — \(String(describing: endDate))")
        presentShareSheet(items: [URL(fileURLWithPath: filePath)])
    }
}

सीमित आकार वाली फ़ाइलें एक्सपोर्ट करें

Swift
let fiveMegabytes: UInt64 = 5 * 1_000_000
AIBudsLogSDK.logService.exportLogs(fiveMegabytes) { paths, _, _, error in
    guard error == nil, let paths, !paths.isEmpty else { return }
    let URLs = paths.map(URL.init(fileURLWithPath:))
    DispatchQueue.main.async { presentShareSheet(items: URLs) }
}

ध्यान दें

  • maxFileSize bytes में है। Demo decimal megabytes को हर MB के लिए 1_000_000 bytes से बदलता है।
  • .console और .oslogger export support नहीं करते; logs collect करने से पहले persistent destination चुनें।
  • Paths मिलने पर भी error को failure मानें; खाली path collection का अर्थ है कोई export artifact नहीं बना।
  • UIActivityViewController main thread पर present करें और iPad पर उसका popover source configure करें।