Jak mogę skanować kody kreskowe w systemie iOS?
Jak mogę po prostu zeskanować kody kreskowe na iPhonie i / lub iPadzie?
11 answers
Wyprodukowaliśmy aplikację "Kody kreskowe" dla iPhone ' a. Może dekodować kody QR. Kod ĹşrĂłdĹ 'owy jest dostÄ ™ pny z projektu zxing ; szczegăłlnie, chcesz przyjrzeÄ ‡ siÄ ™ klientowi iPhone' ai czÄ ™ Ĺ " ciowemu portowi C++ biblioteki rdzenia. Port jest trochę stary, z około 0.9 wydania kodu Javy, ale nadal powinien działać dość dobrze.
Jeśli chcesz przeskanować inne formaty, takie jak formaty 1D, możesz kontynuować port kodu Javy w ten projekt do C++.
EDIT: Kody kreskowe i Kod {[0] } w projekcie zostały wycofane na początku 2014 roku.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-19 03:46:23
Sprawdź ZBar odczytuje kod QR oraz kody ECN / ISBN i jest dostępny na licencji LGPL v2.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-20 15:17:35
Podobnie jak w przypadku wydania iOS7
nie musisz już używać zewnętrznego frameworka ani biblioteki. [[4]}ekosystem iOS z AVFoundation teraz w pełni obsługuje skanowanie prawie każdego kodu od QR przez EAN do UPC.
Oto fajny tutorial , który pokazuje krok po kroku: iPhone QR code Scan library iOS7
Mały przykład jak to ustawić up:
#pragma mark -
#pragma mark AVFoundationScanSetup
- (void) setupScanner;
{
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
self.session = [[AVCaptureSession alloc] init];
self.output = [[AVCaptureMetadataOutput alloc] init];
[self.session addOutput:self.output];
[self.session addInput:self.input];
[self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.preview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
AVCaptureConnection *con = self.preview.connection;
con.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
[self.view.layer insertSublayer:self.preview atIndex:0];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-14 14:49:07
Aparat iPhone 4 to więcej niż capabale robienia kodów kreskowych. Biblioteka kodów kreskowych zebra crossing posiada widelec na github zxing-iphone. To open-source.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-06 14:01:08
Liteqr jest "Lite QR Reader in Objective C ported from zxing" na github i ma wsparcie dla Xcode 4.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-06 15:00:31
Istnieją dwie główne biblioteki:
ZXing biblioteka napisana w Javie, a następnie przeniesiona do Objective C / C++ (tylko kod QR). A inny port do ObjC zostaĹ ' zrobiony przez TheLevelUp: ZXingObjC
ZBar oprogramowanie open source do odczytu kodów kreskowych, oparte na C.
Według moich eksperymentów, ZBar jest o wiele dokładniejszy i szybszy niż ZXing, przynajmniej na iPhonie.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-19 09:11:24
HOWTO: Dodaj czytnik kodów kreskowych do aplikacji iPhone , która wskazuje na ZBar iPhone SDK , wygląda pomocnie (z innego wątku).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 10:31:16
Nie wiem, czy to pomoże, ale oto link do otwartej biblioteki QR Code . Jak widać kilka osób już używało tego do tworzenia aplikacji na iphone ' a.
Wikipedia ma artykuł wyjaśniający czym są kody QR. Moim zdaniem kody QR są znacznie bardziej dopasowane do celu niż standardowy kod kreskowy w przypadku iphone ' a, ponieważ został zaprojektowany do tego typu implementacji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-08 08:17:46
Jeśli Obsługa iPada 2 lub iPoda Touch jest ważna dla Twojej aplikacji, wybrałbym SDK skanera kodów kreskowych, który może dekodować Kody kreskowe w rozmytych obrazach, takich jak nasz Scandit barcode scanner SDK dla iOS i Androida. Dekodowanie rozmazanych obrazów kodów kreskowych jest również pomocne w telefonach z aparatami z autofokusem, ponieważ użytkownik nie musi czekać, aż autofokus zacznie działać.
Scandit jest wyposażony w bezpłatny plan cenowy społeczności, a także posiada API produktów, które ułatwia konwersję numery kodów kreskowych do nazw produktów.
Jest to jedna z najbardziej rozpoznawalnych marek na świecie.]}Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-25 11:49:36
Możesz spojrzeć na kod źródłowy iPhone DataMatrix Reader Stefana Hafenegera (Google Code project; zarchiwizowany post na blogu ), jeśli jest jeszcze dostępny.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-03 02:00:51
Możesz znaleźć inne natywne rozwiązanie iOS za pomocą Swift 4 i Xcode 9 poniżej. Natywny framework AVFoundation
używany w tym rozwiązaniu.
Pierwsza część to podklasa a UIViewController
, która ma powiązane funkcje konfiguracji i obsługi dla AVCaptureSession
.
import UIKit
import AVFoundation
class BarCodeScannerViewController: UIViewController {
let captureSession = AVCaptureSession()
var videoPreviewLayer: AVCaptureVideoPreviewLayer!
var initialized = false
let barCodeTypes = [AVMetadataObject.ObjectType.upce,
AVMetadataObject.ObjectType.code39,
AVMetadataObject.ObjectType.code39Mod43,
AVMetadataObject.ObjectType.code93,
AVMetadataObject.ObjectType.code128,
AVMetadataObject.ObjectType.ean8,
AVMetadataObject.ObjectType.ean13,
AVMetadataObject.ObjectType.aztec,
AVMetadataObject.ObjectType.pdf417,
AVMetadataObject.ObjectType.itf14,
AVMetadataObject.ObjectType.dataMatrix,
AVMetadataObject.ObjectType.interleaved2of5,
AVMetadataObject.ObjectType.qr]
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
setupCapture()
// set observer for UIApplicationWillEnterForeground, so we know when to start the capture session again
NotificationCenter.default.addObserver(self,
selector: #selector(willEnterForeground),
name: .UIApplicationWillEnterForeground,
object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// this view is no longer topmost in the app, so we don't need a callback if we return to the app.
NotificationCenter.default.removeObserver(self,
name: .UIApplicationWillEnterForeground,
object: nil)
}
// This is called when we return from another app to the scanner view
@objc func willEnterForeground() {
setupCapture()
}
func setupCapture() {
var success = false
var accessDenied = false
var accessRequested = false
let authorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
if authorizationStatus == .notDetermined {
// permission dialog not yet presented, request authorization
accessRequested = true
AVCaptureDevice.requestAccess(for: .video,
completionHandler: { (granted:Bool) -> Void in
self.setupCapture();
})
return
}
if authorizationStatus == .restricted || authorizationStatus == .denied {
accessDenied = true
}
if initialized {
success = true
} else {
let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera,
.builtInTelephotoCamera,
.builtInDualCamera],
mediaType: .video,
position: .unspecified)
if let captureDevice = deviceDiscoverySession.devices.first {
do {
let videoInput = try AVCaptureDeviceInput(device: captureDevice)
captureSession.addInput(videoInput)
success = true
} catch {
NSLog("Cannot construct capture device input")
}
} else {
NSLog("Cannot get capture device")
}
}
if success {
DispatchQueue.global().async {
self.captureSession.startRunning()
DispatchQueue.main.async {
let captureMetadataOutput = AVCaptureMetadataOutput()
self.captureSession.addOutput(captureMetadataOutput)
let newSerialQueue = DispatchQueue(label: "barCodeScannerQueue") // in iOS 11 you can use main queue
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: newSerialQueue)
captureMetadataOutput.metadataObjectTypes = self.barCodeTypes
self.videoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)
self.videoPreviewLayer.videoGravity = .resizeAspectFill
self.videoPreviewLayer.frame = self.view.layer.bounds
self.view.layer.addSublayer(self.videoPreviewLayer)
}
}
initialized = true
} else {
// Only show a dialog if we have not just asked the user for permission to use the camera. Asking permission
// sends its own dialog to th user
if !accessRequested {
// Generic message if we cannot figure out why we cannot establish a camera session
var message = "Cannot access camera to scan bar codes"
#if (arch(i386) || arch(x86_64)) && (!os(macOS))
message = "You are running on the simulator, which does not hae a camera device. Try this on a real iOS device."
#endif
if accessDenied {
message = "You have denied this app permission to access to the camera. Please go to settings and enable camera access permission to be able to scan bar codes"
}
let alertPrompt = UIAlertController(title: "Cannot access camera", message: message, preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
self.navigationController?.popViewController(animated: true)
})
alertPrompt.addAction(confirmAction)
self.present(alertPrompt, animated: true, completion: nil)
}
}
}
func handleCapturedOutput(metadataObjects: [AVMetadataObject]) {
if metadataObjects.count == 0 {
return
}
guard let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject else {
return
}
if barCodeTypes.contains(metadataObject.type) {
if let metaDataString = metadataObject.stringValue {
captureSession.stopRunning()
displayResult(code: metaDataString)
return
}
}
}
func displayResult(code: String) {
let alertPrompt = UIAlertController(title: "Bar code detected", message: code, preferredStyle: .alert)
if let url = URL(string: code) {
let confirmAction = UIAlertAction(title: "Launch URL", style: .default, handler: { (action) -> Void in
UIApplication.shared.open(url, options: [:], completionHandler: { (result) in
if result {
NSLog("opened url")
} else {
let alertPrompt = UIAlertController(title: "Cannot open url", message: nil, preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
})
alertPrompt.addAction(confirmAction)
self.present(alertPrompt, animated: true, completion: {
self.setupCapture()
})
}
})
})
alertPrompt.addAction(confirmAction)
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in
self.setupCapture()
})
alertPrompt.addAction(cancelAction)
present(alertPrompt, animated: true, completion: nil)
}
}
Druga część jest rozszerzeniem naszej UIViewController
podklasy dla AVCaptureMetadataOutputObjectsDelegate
, gdzie łapiemy przechwycone wyjścia.
extension BarCodeScannerViewController: AVCaptureMetadataOutputObjectsDelegate {
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
handleCapturedOutput(metadataObjects: metadataObjects)
}
}
Aktualizacja dla Swift 4.2
.UIApplicationWillEnterForeground
zmiany jako UIApplication.willEnterForegroundNotification
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-23 19:06:51