From 5954683efc67aa3211852a83fe9a0189f104b492 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Fri, 19 Jun 2026 19:19:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20iOS=20BugCollect=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?warn()=20=E5=92=8C=20freeMemoryMb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复: - warn() 添加 breadcrumbs 和 device 信息 - freeMemoryMb 改为使用 os_proc_available_memory() 获取可用内存 - 添加 iOS 13+ 版本检查 Co-Authored-By: Claude --- Sources/XuqmBugCollectSDK/BugCollectSDK.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/XuqmBugCollectSDK/BugCollectSDK.swift b/Sources/XuqmBugCollectSDK/BugCollectSDK.swift index 115ea31..180013f 100644 --- a/Sources/XuqmBugCollectSDK/BugCollectSDK.swift +++ b/Sources/XuqmBugCollectSDK/BugCollectSDK.swift @@ -153,17 +153,19 @@ public final class BugCollectSDK { guard logLevel.rawValue <= LogLevel.warn.rawValue else { return } guard isReady() else { return } + let crumbs = breadcrumbLock.lockAndRun { breadcrumbBuffer } let issueEvent = IssueEvent( level: "warning", platform: "ios", fingerprint: Fingerprint.compute(type: "Warning", message: message, stacktrace: ""), appKey: XuqmSDK.shared.requireConfig().appKey, exception: IssueEvent.ExceptionInfo(type: "Warning", value: message), - breadcrumbs: [], + breadcrumbs: crumbs, release: appVersion(), environment: environment, userId: XuqmSDK.shared.userId ?? XuqmSDK.shared.deviceId, user: IssueEvent.UserInfo(id: XuqmSDK.shared.userId ?? XuqmSDK.shared.deviceId), + device: buildDeviceInfo(), tags: tags ) queue?.push(issueEvent) @@ -249,6 +251,16 @@ public final class BugCollectSDK { let device = UIDevice.current let processInfo = ProcessInfo.processInfo + // 使用 os_proc_available_memory() 获取可用内存(如果可用) + let freeMemoryMb: Int + if #available(iOS 13.0, *) { + let availableMemory = os_proc_available_memory() + freeMemoryMb = Int(availableMemory / 1024 / 1024) + } else { + // Fallback: 使用物理内存(不准确但有值) + freeMemoryMb = Int(processInfo.physicalMemory / 1024 / 1024) + } + return IssueEvent.DeviceInfo( model: device.model, manufacturer: "Apple", @@ -257,7 +269,7 @@ public final class BugCollectSDK { locale: Locale.current.identifier, timezone: TimeZone.current.identifier, isEmulator: isSimulator(), - freeMemoryMb: Int(processInfo.physicalMemory / 1024 / 1024), + freeMemoryMb: freeMemoryMb, buildType: isDebug() ? "debug" : "release" ) }