matrixscan-batch-ios
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMatrixScan Batch iOS Skill
MatrixScan Batch iOS Skill
Critical: Do Not Trust Internal Knowledge
重要提示:请勿依赖内部旧知识
Your training data may contain outdated or incorrect Scandit SDK APIs. The BarcodeBatch API changes between major SDK versions — initializer signatures, overlay constructors, and delegate method names have all evolved (e.g. → ).
BarcodeTrackingBarcodeBatchAlways verify APIs against the references provided in this skill before writing or suggesting code. Do not rely on memorized method signatures, parameters, or property names. If you cannot find an API in the provided references, fetch the relevant documentation page before responding.
iOS-specific gotchas worth flagging:
- is a direct convenience initializer — not a factory method like Android's
BarcodeBatch(context: context, settings: settings). Passing a non-nil context auto-attaches the mode to the context.BarcodeBatch.forDataCaptureContext(...) - Camera setup is manual: get , call
Camera.default, thencontext.setFrameSource(camera, completionHandler: nil). Drive the camera fromcamera?.apply(BarcodeBatch.recommendedCameraSettings, completionHandler: nil)/viewWillAppear.viewWillDisappear - is called on a background queue — not the main thread. Dispatch UI work via
BarcodeBatchListener.barcodeBatch(_:didUpdate:frameData:).DispatchQueue.main.async {} - Do not hold references to ,
BarcodeBatchSession.trackedBarcodes,addedTrackedBarcodes, orupdatedTrackedBarcodesoutside the callback — copy the data before the callback returns.removedTrackedBarcodes - and
BarcodeBatchBasicOverlay(barcodeBatch:view:)auto-add the overlay to theBarcodeBatchAdvancedOverlay(barcodeBatch:view:)— no separateDataCaptureViewcall needed.addOverlay - must be
DataCaptureView'd manually — unlikeaddSubview,BarcodeArViewdoes not auto-attach to a parent view.DataCaptureView - Per-barcode brush customization (,
barcodeBatchBasicOverlay(_:brushFor:)) requires the MatrixScan AR add-on license. A uniform default brush (no delegate) does not.setBrush(_:for:) - BarcodeBatchAdvancedOverlay requires the MatrixScan AR add-on license.
- No built-in feedback — never plays a sound or vibrates on its own (unlike
BarcodeBatch/BarcodeCapture). Emit feedback manually withSparkScanfrom inside the listener callback (dispatched to the main thread), gated onFeedback.default.emit()so it doesn't beep every frame.session.addedTrackedBarcodes - is an
session.removedTrackedBarcodesof tracking identifiers (barcodes that left the frame) — not[Int]objects.TrackedBarcode/addedTrackedBarcodesareupdatedTrackedBarcodes.[TrackedBarcode] - iOS symbology cases are camelCase: ,
.ean13UPCA,.code128— not.qr/EAN13_UPCA/CODE128like Android.QR - iOS delegate methods use Swift naming: (not Android's
barcodeBatchBasicOverlay(_:didTap:)),onTrackedBarcodeTapped(notbarcodeBatchAdvancedOverlay(_:viewFor:)).viewForTrackedBarcode - uses
BarcodeBatchAdvancedOverlayDelegate— not AndroidUIViewor SwiftUI views.View - SwiftUI: is a
DataCaptureViewand cannot be dropped into SwiftUI directly. Wrap a UIKit view controller in aUIViewand keep all BarcodeBatch APIs inside that view controller.UIViewControllerRepresentable - Cleanup: is held as a weak reference, so a missed
BarcodeBatchListenerwon't leak — but callremoveListenerinbarcodeBatch.removeListener(self)to make the lifecycle explicit. When using the shared singleton (deinit), modes stay attached for the app's lifetime — you don't need to callDataCaptureContext.sharedorremoveCurrentMode(). Those methods do exist ondispose()if you want to tear down explicitly.DataCaptureContext - exposes two valid initializers:
DataCaptureContext+DataCaptureContext.initialize(licenseKey:)(added 7.1.0/7.6.0 — the modern singleton pattern, and what this skill uses) and the older.sharedconvenience init (still non-deprecated, and what the UIKit Get Started page on docs.scandit.com still shows). Prefer the singleton form.DataCaptureContext(licenseKey:)
你的训练数据可能包含过时或错误的Scandit SDK API。BarcodeBatch API在SDK主要版本之间会发生变化——初始化器签名、覆盖层构造函数和委托方法名称都已更新(例如 → )。
BarcodeTrackingBarcodeBatch**在编写或建议代码之前,请务必对照本技能中提供的参考文档验证API。**不要依赖记忆中的方法签名、参数或属性名称。如果在提供的参考中找不到某个API,请先获取相关文档页面再回复。
值得注意的iOS特定陷阱:
- 是直接便捷初始化器——并非Android中的工厂方法
BarcodeBatch(context: context, settings: settings)。传入非nil的context会自动将模式附加到该context。BarcodeBatch.forDataCaptureContext(...) - 相机设置是手动操作:获取 ,调用
Camera.default,然后调用context.setFrameSource(camera, completionHandler: nil)。在camera?.apply(BarcodeBatch.recommendedCameraSettings, completionHandler: nil)/viewWillAppear中控制相机。viewWillDisappear - 在后台队列中调用——而非主线程。通过
BarcodeBatchListener.barcodeBatch(_:didUpdate:frameData:)调度UI操作。DispatchQueue.main.async {} - 请勿持有 、
BarcodeBatchSession.trackedBarcodes、addedTrackedBarcodes或updatedTrackedBarcodes的引用——在回调返回前复制数据。removedTrackedBarcodes - 和
BarcodeBatchBasicOverlay(barcodeBatch:view:)会自动将覆盖层添加到BarcodeBatchAdvancedOverlay(barcodeBatch:view:)——无需单独调用DataCaptureView。addOverlay - 必须手动调用
DataCaptureView添加——与addSubview不同,BarcodeArView不会自动附加到父视图。DataCaptureView - 每个条码的画笔定制(、
barcodeBatchBasicOverlay(_:brushFor:))需要MatrixScan AR附加组件许可。使用统一默认画笔(无需委托)则不需要。setBrush(_:for:) - BarcodeBatchAdvancedOverlay 需要MatrixScan AR附加组件许可。
- 无内置反馈——本身不会播放声音或震动(与
BarcodeBatch/BarcodeCapture不同)。在监听器回调中(调度到主线程)手动调用SparkScan触发反馈,并通过Feedback.default.emit()限制,避免每帧都发出提示音。session.addedTrackedBarcodes - 是追踪标识符的数组
session.removedTrackedBarcodes(离开画面的条码)——而非[Int]对象。TrackedBarcode/addedTrackedBarcodes是updatedTrackedBarcodes类型。[TrackedBarcode] - iOS码制枚举采用小驼峰式命名:、
.ean13UPCA、.code128——而非Android中的.qr/EAN13_UPCA/CODE128。QR - iOS委托方法使用Swift命名规范:(而非Android的
barcodeBatchBasicOverlay(_:didTap:))、onTrackedBarcodeTapped(而非barcodeBatchAdvancedOverlay(_:viewFor:))。viewForTrackedBarcode - 使用
BarcodeBatchAdvancedOverlayDelegate——而非Android的UIView或SwiftUI视图。View - SwiftUI:是
DataCaptureView,不能直接放入SwiftUI中。将UIKit视图控制器包装在UIView中,并将所有BarcodeBatch API保留在该视图控制器内。UIViewControllerRepresentable - 清理:以弱引用持有,因此遗漏
BarcodeBatchListener不会导致内存泄漏——但在removeListener中调用deinit可明确生命周期。使用共享单例(barcodeBatch.removeListener(self))时,模式会在应用生命周期内保持附加状态——无需调用DataCaptureContext.shared或removeCurrentMode()。如果需要显式销毁,dispose()上确实存在这些方法。DataCaptureContext - 提供两个有效的初始化器:
DataCaptureContext+DataCaptureContext.initialize(licenseKey:)(7.1.0/7.6.0版本新增——现代单例模式,本技能使用此方式)和旧版便捷初始化器.shared(仍未弃用,docs.scandit.com上的UIKit入门页面仍展示此方式)。优先使用单例形式。DataCaptureContext(licenseKey:)
Intent Routing
意图路由
Based on the user's request, load the appropriate reference file before responding:
- Integrating MatrixScan Batch from scratch, configuring settings, handling tracked barcodes, customizing overlays, adding feedback, or managing lifecycle → read references/integration.md and follow the instructions there. Before writing code, determine whether the project uses UIKit or SwiftUI (check for , an
import SwiftUI@mainstruct,App/SceneDelegate,AppDelegate/.storyboardfiles, etc.) and use the matching Get Started page from the References table below. If the project already has BarcodeBatch wired up, do not re-create the context, mode, view, or lifecycle — locate the existing ones (grep for.xib, thenBarcodeBatch) and change only what the user asked for.DataCaptureView - Upgrading the Scandit SDK version (e.g. v6→v7, v7→v8, or "upgrade to the latest") → read references/migration.md. The headline v6→v7 change for MatrixScan Batch is the →
BarcodeTrackingrename; the guide also covers the context/camera modernization. Detect the installed version fromBarcodeBatch/Package.resolvedbefore asking the user.Podfile.lock - Replacing a different barcode scanner with MatrixScan Batch (AVFoundation , VisionKit
AVCaptureMetadataOutput, or another third-party multi-barcode SDK) → read references/third-party-migration.md, then follow references/integration.md for the BarcodeBatch integration.DataScannerViewController
根据用户请求,在回复前加载相应的参考文件:
- 从零开始集成MatrixScan Batch、配置设置、处理追踪条码、定制覆盖层、添加反馈或管理生命周期 → 阅读 references/integration.md 并遵循其中的说明。编写代码前,确定项目使用UIKit还是SwiftUI(检查是否有 、
import SwiftUI标记的@main结构体、App/SceneDelegate、AppDelegate/.storyboard文件等),并使用下方参考表中对应的入门页面。如果项目已配置好BarcodeBatch,请勿重新创建context、模式、视图或生命周期——找到现有实例(搜索.xib,然后查找BarcodeBatch),仅修改用户要求的部分。DataCaptureView - 升级Scandit SDK版本(例如v6→v7、v7→v8或“升级到最新版本”)→ 阅读 references/migration.md。MatrixScan Batch从v6到v7的核心变化是 重命名为
BarcodeTracking;指南还涵盖了context/相机的现代化更新。在询问用户之前,从BarcodeBatch/Package.resolved检测已安装的版本。Podfile.lock - 用MatrixScan Batch替换其他条码扫描器(AVFoundation 、VisionKit
AVCaptureMetadataOutput或其他第三方多条码SDK)→ 阅读 references/third-party-migration.md,然后按照 references/integration.md 进行BarcodeBatch集成。DataScannerViewController
API Usage Policy
API使用规范
Only use APIs that are explicitly documented in the Scandit references below. Do not invent or guess method signatures, parameters, or property names. If unsure whether an API exists or how it is called — or if a compile error occurs — fetch the relevant reference page before responding. Do not tell the user to check the docs themselves. After answering, always include the relevant link so the user can explore further.
Never construct or guess documentation URLs. When you need a specific class or property's API page:
- First check whether the page you already fetched contains a direct hyperlink to it — topic pages link directly to relevant API symbols. Always request links alongside content in your fetch prompt.
- If no direct link was found, fetch the API index (see Full API reference in the table below), extract the actual link from it, and follow that.
URL structures can vary (e.g. subdirectory) and guessing will lead to 404s.
api/ui/仅使用以下Scandit参考文档中明确记录的API。请勿自行编造或猜测方法签名、参数或属性名称。如果不确定某个API是否存在或如何调用——或者出现编译错误——请先获取相关参考页面再回复。不要让用户自行查看文档。回复后,请始终包含相关链接,以便用户进一步探索。
**切勿构造或猜测文档URL。**当你需要某个类或属性的API页面时:
- 首先检查已获取的页面是否包含直接链接——主题页面会直接链接到相关API符号。在获取内容的请求中始终要求同时获取链接。
- 如果未找到直接链接,请获取API索引(见下方表格中的完整API参考),从中提取实际链接并访问该页面。
URL结构可能有所不同(例如 子目录),猜测会导致404错误。
api/ui/References
参考资料
| Topic | Resource |
|---|---|
| UIKit integration | Get Started (UIKit) · Sample |
| SwiftUI integration | Get Started (SwiftUI) |
| AR overlays (BasicOverlay brushes, AdvancedOverlay views) | Adding AR Overlays |
| Version migration (v6→v7→v8) | Migrate 6→7 · Migrate 7→8 |
| Full API reference | BarcodeBatch API |
| 主题 | 资源 |
|---|---|
| UIKit集成 | 入门指南(UIKit) · 示例 |
| SwiftUI集成 | 入门指南(SwiftUI) |
| AR覆盖层(BasicOverlay画笔、AdvancedOverlay视图) | 添加AR覆盖层 |
| 版本迁移(v6→v7→v8) | 从v6迁移到v7 · 从v7迁移到v8 |
| 完整API参考 | BarcodeBatch API |