如何在 iOS 上扫描条形码?
如何在 iPhone 和/或 iPad 上简单地扫描条形码?
How can I simply scan barcodes on iPhone and/or iPad?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 iPhone 和/或 iPad 上简单地扫描条形码?
How can I simply scan barcodes on iPhone and/or iPad?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
我们为 iPhone 制作了“条形码”应用程序。 它可以解码 QR 码。 源代码可从 zxing 项目获取; 具体来说,您需要查看 iPhone 客户端 和核心库的部分 C++ 移植。 该端口有点旧,大约是 Java 代码 0.9 版本的版本,但应该仍然可以很好地工作。
如果您需要扫描其他格式,例如一维格式,您可以继续将此项目中的 Java 代码移植到 C++。
编辑:项目中的条形码和
iphone
代码于 2014 年初停用。We produced the 'Barcodes' application for the iPhone. It can decode QR Codes. The source code is available from the zxing project; specifically, you want to take a look at the iPhone client and the partial C++ port of the core library. The port is a little old, from circa the 0.9 release of the Java code, but should still work reasonably well.
If you need to scan other formats, like 1D formats, you could continue the port of the Java code within this project to C++.
EDIT: Barcodes and the
iphone
code in the project were retired around the start of 2014.随着
iOS7
的发布,您不再需要使用外部框架或库。 带有 AVFoundation 的 iOS 生态系统现在完全支持扫描从 QR over EAN 到 UPC 的几乎所有代码。只需查看技术说明和 AVFoundation 编程指南即可。
AVMetadataObjectTypeQRCode
是您的朋友。这是一个很好的教程,它逐步展示了它:
iPhone QR 码扫描库 iOS7
只是一个关于如何设置它的小例子向上:
As with the release of
iOS7
you no longer need to use an external framework or library. The iOS ecosystem with AVFoundation now fully supports scanning almost every code from QR over EAN to UPC.Just have a look at the Tech Note and the AVFoundation programming guide.
AVMetadataObjectTypeQRCode
is your friend.Here is a nice tutorial which shows it step by step:
iPhone QR code scan library iOS7
Just a little example on how to set it up:
有两个主要的库:
ZXing 一个用 Java 编写然后移植到 Objective 的库C / C++(仅限二维码)。 TheLevelUp 已经完成了 ObjC 的另一个移植: ZXingObjC
ZBar 一个用于读取条形码的开源软件,基于 C。
根据我的实验,ZBar 比 ZXing 更加准确和快速,至少在 iPhone 上是这样。
There are two major libraries:
ZXing a library written in Java and then ported to Objective C / C++ (QR code only). And an other port to ObjC has been done, by TheLevelUp: ZXingObjC
ZBar an open source software for reading bar codes, C based.
According to my experiments, ZBar is far more accurate and fast than ZXing, at least on iPhone.
您可以在下面找到另一个使用 Swift 4 和 Xcode 9 的原生 iOS 解决方案。 本解决方案中使用的本机 AVFoundation 框架。
第一部分是 UIViewController 的子类,它具有 AVCaptureSession 的相关设置和处理函数。
第二部分是
AVCaptureMetadataOutputObjectsDelegate
的UIViewController
子类的扩展,我们在其中捕获捕获的输出。Swift 4.2 更新
.UIApplicationWillEnterForeground
更改为UIApplication.willEnterForegroundNotification
。You can find another native iOS solution using Swift 4 and Xcode 9 at below. Native
AVFoundation
framework used with in this solution.First part is the a subclass of
UIViewController
which have related setup and handler functions forAVCaptureSession
.Second part is the extension of our
UIViewController
subclass forAVCaptureMetadataOutputObjectsDelegate
where we catch the captured outputs.Update for Swift 4.2
.UIApplicationWillEnterForeground
changes asUIApplication.willEnterForegroundNotification
.如果对 iPad 2 或 iPod Touch 的支持对您的应用程序很重要,我会选择可以解码模糊图像中的条形码的条形码扫描仪 SDK,例如我们的 适用于 iOS 和 Android 的 Scandit 条码扫描器 SDK。 解码模糊的条形码图像对于带有自动对焦摄像头的手机也很有帮助,因为用户不必等待自动对焦启动。Scandit
附带免费的社区价格计划,并且还具有产品 API,可以轻松将条形码数字转换为产品名称。
(免责声明:我是 Scandit 的联合创始人)
If support for the iPad 2 or iPod Touch is important for your application, I'd choose a barcode scanner SDK that can decode barcodes in blurry images, such as our Scandit barcode scanner SDK for iOS and Android. Decoding blurry barcode images is also helpful on phones with autofocus cameras because the user does not have to wait for the autofocus to kick in.
Scandit comes with a free community price plan and also has a product API that makes it easy to convert barcode numbers into product names.
(Disclaimer: I'm a co-founder of Scandit)
iPhone 摄像头的问题在于,第一批型号(已大量使用)具有定焦摄像头,无法在 2 英尺以下的距离内对焦拍照。 图像模糊且扭曲,如果从较远的距离拍摄,则条形码中没有足够的细节/信息。
一些公司已经开发了 iPhone 应用程序,可以通过使用先进的去模糊技术来实现这一点。 您可以在 Apple 应用商店中找到这些应用程序:pic2shop、RedLaser 和 ShopSavvy。 所有公司都宣布他们还提供 SDK - 有些是免费的或非常优惠的条件,请检查一下。
The problem with iPhone camera is that the first models (of which there are tons in use) have a fixed-focus camera that cannot take picture in-focus for distances under 2ft. The images are blurry and distorted and if taken from greater distance there is not enough detail/information from the barcode.
A few companies have developed iPhone apps that can accomodate for that by using advanced de-blurring technologies. Those applications you can find on Apple app store: pic2shop, RedLaser and ShopSavvy. All of the companies have announced that they have also SDKs available - some for free or very preferential terms, check that one out.
使用Swift 5,它简单且超级快!
您只需要添加可可豆荚“BarcodeScanner”,这里是完整的代码
确保在您的.plist文件中添加相机权限
并在您的ViewController中添加扫描仪并以这种方式处理结果
仍然以及任何问题或挑战,请在此处查看示例应用程序及其完整源代码
with Swift 5 it's Simple and Super fast!!
You just need to add cocoa pods "BarcodeScanner" here is the full code
Make sure add Camera permission in your .plist file
And add Scanner and handle result in your ViewController this way
Still and any question or challenges, please check sample application here with full source code
我相信这可以使用 AVFramework 来完成,这里是执行此操作的示例代码
I believe this can be done using AVFramework, here is the sample code to do this
这是简单的代码:
Here is simple code:
如果您正在使用 Swift 4 为 iOS > 10.2 进行开发,那么您可以尝试我的解决方案。 我混淆了 这个 和 this 教程并提出了一个 ViewController,它可以扫描 QR 码并
print()
将其输出。 我的用户界面中还有一个开关来切换相机灯,可能也会有帮助。 目前我只在 iPhone SE 上进行了测试,如果它不适用于较新的 iPhone,请告诉我。干得好:
If you are developing for iOS >10.2 with Swift 4 then you can try my solution. I mixed up this and this tutorial and came up with a ViewController which scans a QR Code and
print()
it out. I also have a Switch in my UI to toggle the camera light, might be helpful as well. For now I only tested it on a iPhone SE, please let me know if it doesn't work on newer iPhones.Here you go:
您可以检查 ZBarSDK 来读取 QR 码和 ECN/ISBN 码,集成很简单,请尝试以下代码。
在 didFinishPickingMediaWithInfo 中我们得到条形码值。
you can check ZBarSDK to reads QR Code and ECN/ISBN codes it's simple to integrate try the following code.
and in didFinishPickingMediaWithInfo we get bar code value.
最简单的方法是使用可改进的最小 UI 的第三方框架。 检查 QRCodeScanner83
您可以简单地使用以下代码(查看有关如何在故事板中创建视图控制器的文档):
The simplest way is to use 3rd party framework with minimum UI that can be improved. Check QRCodeScanner83
You can simply use the following code (check the documentation on how to create view controller in your storyboard):