yannickl / qrcodereader.swift Goto Github PK
View Code? Open in Web Editor NEWSimple QRCode reader in Swift
License: MIT License
Simple QRCode reader in Swift
License: MIT License
Hi i try generate vcard qr .But when the qr content is larger, the qr reader is not able to detect. Any solution?example
http://postimg.org/image/g2t534lzb/
Hello Guys,
I am using this barcode reader and it seems very good but i am facing one issue with CODE-128 type. I am attaching screenshot with highlighting two different barcodes but with same type CODE-128. The green one is very easily readable within a second but i am facing difficulty with red one. It takes a lot of time to read with 90% failure rate.I am using version 6.0 and i need very urgent help. Your help will be appreciated. Thanks
As per subject, why it happen? It suddenly not scanning at all if 1 second earlier. If more than 1 second, it scan successfully.
I got this error message when I try to navigate another view controller if qr code detected.
2015-01-20 10:39:49.474 *[228:9160] Warning: Attempt to present * on * whose view is not in the window hierarchy!
My code
`
@IBAction func btnQrCode(sender: AnyObject) {
reader.modalPresentationStyle = .FormSheet
reader.delegate = self
reader.completionBlock = { (result: String?) in
println(result)
if result != nil {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let successViewController = storyBoard.instantiateViewControllerWithIdentifier("successView") as SuccessViewController
self.presentViewController(successViewController, animated:true, completion:nil)
}
}
presentViewController(reader, animated: true, completion: nil)
}
`
Related to issue 23 #23
I want to use your reader but need to provide my own UI overlay so I need to insert codeReader.previewLayer onto my own view.
But QRCodeReaderViewController's codeReader uses the default access modifier which is 'internal'. Could you change it to 'public' so that we can access it
As per subject, I got this error message on this line
import UIKit
/// Overlay over the camera view to display the area (a square) where to scan the code
final class ReaderOverlayView: UIView {
private var overlay: CAShapeLayer = {
var overlay = CAShapeLayer()
overlay.backgroundColor = UIColor.clearColor().CGColor
overlay.fillColor = UIColor.clearColor().CGColor
overlay.strokeColor = UIColor.whiteColor().CGColor
overlay.lineWidth = 3
overlay.lineDashPattern = [7.0, 7.0]
overlay.lineDashPhase = 0
return overlay
}()
override init() { //error here
super.init() //error here
layer.addSublayer(overlay)
}
Hi I have the error
UIViewController does not conform to protocol QRCodeReaderViewControllerDelegate
While I have implemented every required method
func reader(reader: QRCodeReaderViewController, didScanResult result: String) {
self.dismissViewControllerAnimated(true, completion: { [unowned self] () -> Void in
let alert = UIAlertController(title: "QRCodeReader", message: result, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
})
}
func readerDidCancel(reader: QRCodeReaderViewController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
What could be the problem here?
Hey, i get this Error Message when starting your Example Project on Xcode 6.1.1
QRCodeReader.swift[70320:1605607] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use -availableMetadataObjectTypes.'
thanks for your help
I am new with swift, and try develop a simple app for IPad2 with read a QRCode, I create this code:
//
// ViewController.swift
// Minha Primeira Interface
//
// Created by Carlos Delfino on 17/09/15.
// Copyright © 2015 Carlos Delfino. All rights reserved.
//
import UIKit
import AVFoundation
import QRCodeReader
class ViewController: UIViewController, QRCodeReaderViewControllerDelegate{
// MARK: properties
@IBOutlet weak var loginTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginButton: UIButton!
@IBOutlet weak var logoffButton: UIButton!
@IBOutlet weak var consultDocumentButton: UIButton!
@IBOutlet weak var loginMsg: UILabel!
@IBOutlet var loginView: UIView!
@IBOutlet var documentConsultView: UIView!
var user: User?
// Good practice: create the reader lazily to avoid cpu overload during the
// initialization and each time we need to scan a QRCode
lazy var reader = QRCodeReaderViewController(metadataObjectTypes: [AVMetadataObjectTypeQRCode])
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: Actions
@IBAction func doLogin(sender: UIButton) {
loginMsg.hidden = true
if(loginTextField.text == "CarlosDelfino"){
user = User(name: "CarlosDelfino")
}else{
loginMsg.text = "Falha no Login, não foi encontrada as credenciais informadas"
loginMsg.hidden = false
user = nil
}
passwordTextField.text = ""
}
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
var show = false;
if (user == nil && identifier == "FromLoginToConsultDocument_Login") {
show = false
}else if (identifier == "FromConsultDocumentToLogin_Logout"){
show = true
}else{
show = true
}
return show;
}
@IBAction func doConsultDocument(sender: UIButton){
// Retrieve the QRCode content
// By using the delegate pattern
reader.delegate = self
// Or by using the closure pattern
reader.completionBlock = { (result: String?) in
print(result)
}
// Presents the reader as modal form sheet
reader.modalPresentationStyle = .FormSheet
presentViewController(reader, animated: true, completion: nil)
}
@IBAction func doLogout(sender: UIButton) {
user = nil
}
// MARK: - QRCodeReader Delegate Methods
/**
Tells the delegate that the reader did scan a code.
- parameter reader: A code reader object informing the delegate about the scan result.
- parameter result: The result of the scan
*/
func reader(reader: QRCodeReaderViewController, didScanResult result: String){
self.dismissViewControllerAnimated(true, completion: nil)
}
/**
Tells the delegate that the user wants to stop scanning codes.
- parameter reader: A code reader object informing the delegate about the cancellation.
*/
func readerDidCancel(reader: QRCodeReaderViewController){
self.dismissViewControllerAnimated(true, completion: nil)
}
}
but where I click on button "Consultar Documento", and call handle action "doConsultDocument(UIButton) I get this exception:
2015-09-19 16:02:33.344 Minha Primeira Interface[7980:4477032] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMetadataOutput setMetadataObjectTypes:] - unsupported type found. Use -availableMetadataObjectTypes.'
*** First throw call stack:
(
0 CoreFoundation 0x00611a94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02213e02 objc_exception_throw + 50
2 AVFoundation 0x002ff82e -[AVCaptureMetadataOutput setMetadataObjectTypes:] + 500
3 QRCodeReader 0x0017ca89 _TFC12QRCodeReader12QRCodeReaderP33_B9DC3D797F478C8B92B825BD13CC602626configureDefaultComponentsfS0_FT_T_ + 617
4 QRCodeReader 0x0017c76f _TFC12QRCodeReader12QRCodeReadercfMS0_FT19metadataObjectTypesGSaSS__S0_ + 495
5 QRCodeReader 0x0017c80b _TFC12QRCodeReader12QRCodeReaderCfMS0_FT19metadataObjectTypesGSaSS__S0_ + 91
6 QRCodeReader 0x00182efc _TFC12QRCodeReader26QRCodeReaderViewControllercfMS0_FT17cancelButtonTitleSS19metadataObjectTypesGSaSS_19startScanningAtLoadSb_S0_ + 108
7 QRCodeReader 0x00182d36 _TFC12QRCodeReader26QRCodeReaderViewControllercfMS0_FT19metadataObjectTypesGSaSS_19startScanningAtLoadSb_S0_ + 182
8 QRCodeReader 0x00182e02 _TFC12QRCodeReader26QRCodeReaderViewControllerCfMS0_FT19metadataObjectTypesGSaSS_19startScanningAtLoadSb_S0_ + 98
9 Minha Primeira Interface 0x000c4152 _TFC24Minha_Primeira_Interface14ViewControllerg6readerC12QRCodeReader26QRCodeReaderViewController + 386
10 Minha Primeira Interface 0x000c4ec2 _TFC24Minha_Primeira_Interface14ViewController17doConsultDocumentfS0_FCSo8UIButtonT_ + 50
11 Minha Primeira Interface 0x000c53ad _TToFC24Minha_Primeira_Interface14ViewController17doConsultDocumentfS0_FCSo8UIButtonT_ + 61
12 libobjc.A.dylib 0x022280b5 -[NSObject performSelector:withObject:withObject:] + 84
13 UIKit 0x00df4c40 -[UIApplication sendAction:to:from:forEvent:] + 118
14 UIKit 0x00df4bbf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
15 UIKit 0x00f8a8fc -[UIControl sendAction:to:forEvent:] + 79
16 UIKit 0x00f8ac7c -[UIControl _sendActionsForEvents:withEvent:] + 408
17 UIKit 0x00f89c87 -[UIControl touchesEnded:withEvent:] + 714
18 UIKit 0x00e6beb8 -[UIWindow _sendTouchesForEvent:] + 1095
19 UIKit 0x00e6cda4 -[UIWindow sendEvent:] + 1118
20 UIKit 0x00e159b3 -[UIApplication sendEvent:] + 266
21 UIKit 0x00dec903 _UIApplicationHandleEventQueue + 7327
22 CoreFoundation 0x0052be7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x00521b0b __CFRunLoopDoSources0 + 523
24 CoreFoundation 0x00520f28 __CFRunLoopRun + 1032
25 CoreFoundation 0x00520866 CFRunLoopRunSpecific + 470
26 CoreFoundation 0x0052067b CFRunLoopRunInMode + 123
27 GraphicsServices 0x04e85664 GSEventRunModal + 192
28 GraphicsServices 0x04e854a1 GSEventRun + 104
29 UIKit 0x00df2cc1 UIApplicationMain + 160
30 Minha Primeira Interface 0x000c782c main + 140
31 libdyld.dylib 0x053faa21 start + 1
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
´´´
When installing using CocoaPods, xcode offers to convert to Swift 3. I tried pointing to the tip of the master like so, but without any luck:
pod 'QRCodeReader.swift', :git => 'https://github.com/yannickl/QRCodeReader.swift' #point to master to get swift 3 version.
Browsing the files here on github, it seems they do not comply with the Swift 3 syntax that xcode 8 enforces (e.g. replacing public with open, private with fileprivate).
The QR Code read is too fast, I can't even position my phone correctly, so it often get a nil result back.
Is there any way to set a delay or a NSTimer to give the app more time to focus and positon the phone correctly?
I used the same kind of code in my application. It takes some time in reading the code. What could be the reason and its solution. Do I need to use ZXing kind of third party library for this?
Added pod into podfile as were shown.
pod 'QRCodeReader.swift', '~> 6.1.0'
when run: pod install get this error:
None of your spec sources contain a spec satisfying the dependency: QRCodeReader.swift (~> 6.1.0)
.
I kinda need only a scanner view (no cancel button and no switch to front camera button) to be displayed on a screen. So I added this method:
public func returnCameraView () -> UIView {
return cameraView;
}
I believe that adding only a clean scanner view to my view controller would be more preferable for the component.
If I scanned a vcard, how am I able to automatically create a contact based on the vcard, or is there any way for me to workaround?
My app is crashing on some specific devices in production. This is the line where it crashes.
QRCodeReader: function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of static QRCodeReader.QRCodeReader.supportsMetadataObjectTypes (QRCodeReader.QRCodeReader.Type)([Swift.String]?) -> Swift.Bool + 2408
Thank you for adding metadataObjectTypes selection.
I would be happy if you add "All types" option for that.
As you know, 1D barcodes are very much mixed up. code39, code128, ......
Beginners appreciate capable apps, experts appreciate efficient apps, but they know how to save memory.
Please consider.
Thank you. Hiro
I don't know why it happens like this after I updated my xcode to 6.3.1 and pod. I got this strange error message suddenly even your library already included inside pod.
/Users/MNurdin/Documents/iOS/xxxxx/Controllers/MethodViewController.swift:13:47: Use of undeclared type 'QRCodeReaderViewControllerDelegate'
My code
import UIKit
import CoreData
import AVFoundation
class MethodViewController: UIViewController, QRCodeReaderViewControllerDelegate { //error here
Please advice. Thank you.
Hi,
First, thanks for your nice work :)
In my app, I need to read different types of codes, and depending on the type of the scanned code, I need to substring the resulting string code. And, I might have missed something but I did not managed to get the type of the scanned code read (_readableCodeObject.type).
For people who need to read different types of codes, would it be possible to add the type of the code actually read ?
The problem is : the output will not result in a String? anymore...
is it compatible with swift 2.3 in iOS 8.0 ?
I am trying to use CocoaPods for the first time. First impression is VERY GOOD.
But it gives some errors.
Warning: no rule to process file '/Users/xxxx/x/Pods/QRCodeReader.swift/README.md' of type net.daringfireball.markdown for architecture i386
XCODE thinks README.md should be compiled but he does not know how to.
Maybe it is caused by CocoaPads, but I think it is better to mention in the manual at "Installation" area to remove README.md from "Build Phases->Compile Sources" in the project file.
Unless this problem is happening only on me.
Hiro
Build Failed !!!
Hi guy , in QRCodeReader.swift -> return .defaultDevice(withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .front) failed !!!
I have opened your project from Examples/QRCodeReader.swift.xcodeproj, but it does not appear to scan codes. I have a basic QR code in the center of the rectangle, but I cannot seem to get it to display the text encoded in the QR code.
Is there a way for it to not recognize QRCodes while still showing the camera view?
Hi @yannickl ,
Your library was so great, I'm using it in my applications. Just want to know if are you considering to update this in the latest Xcode and Swift versions ?
Thanks.
I tried the swift3
branch today, and encountered many issues where it would not compile under Xcode 8.0 ß6 / Swift 3.0 / iOS 10
I was able to make the updates to get Framework compiling/working in Swift 3. I created this issue so to track this and will generate a PR.
Is it possible to change the camera icon? Because it does not fit into my design
Hi, I'm new to swift n xcode..
Thx for the qrcodereader pod and it works perfectly fine.
My question is, if I want to use front camera as default, or remove "cancel" words...
I'm going to run its next line after get QR code.
However, my code is already run the next line while show the camera view.
Help me, please. Sorry for my bad english.
My code is as follows.
func myFunc(){
getQRCode()
if self.myQRCode == nil { // self.myQRCode always hasn't readed code ...?????
.......
} else {
}
}
func getQRCode(){
reader.delegate = self
// Or by using the closure pattern
reader.completionBlock = { (result: String?) in
self.myQRCode = result
}
// Presents the reader as modal form sheet
reader.modalPresentationStyle = .FormSheet
presentViewController(reader, animated: true, completion: nil)
}
Often with small codes, the scanner is not able to focus properly. Is there a way to add a "tap to focus" behavior on the AVCaptureView?
Hi,
thanks for this great pod! I'm using your project for an iPhone app and I want to hide the status bar in the modally presented QR scanner view? Is there any way to hide the status bar in the QRCodeReaderViewController?
Thanks!
Best
Alex
Can you please give an example how to use TorchToggle and SwitchCameraButton? Thank you
I've installed using CocoaPods 7.0.0.
Xcode 8 wants to migrate QRCodeReader to Swift 3 but then won't let me as some of the files are locked as it is a CocoaPod.
If I say no to Swift 3 migration then it won't compile my code as it doesn't think QRCodeReader exists.
Hi all,
I've integrated using the classes, because CocoaPods didn't work.
Now I'm having this error : does not conform to protocol qrcodereaderviewcontrollerdelegate
And here's my class beginning code :
class DeskBookingViewController: UIViewController, QRCodeReaderViewControllerDelegate, BookableDelegate {
What's wrong here ?
Thanks,
QRCodeReaderViewControllerDelegate
import AVFoundation
QRCodeReaderViewControllerDelegate
implementations is: lazy var readerVC = QRCodeReaderViewController(metadataObjectTypes: [AVMetadataObjectTypeQRCode])
@IBAction func scanAction(sender: AnyObject) {
// Retrieve the QRCode content
// By using the delegate pattern
readerVC.delegate = self
// Or by using the closure pattern
readerVC.completionBlock = { (result: QRCodeReaderResult?) in
print(result)
}
// Presents the readerVC as modal form sheet
readerVC.modalPresentationStyle = .FormSheet
presentViewController(readerVC, animated: true, completion: nil)
}
// MARK: - QRCodeReader Delegate Methods
func reader(reader: QRCodeReaderViewController, didScanResult result: QRCodeReaderResult) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func readerDidCancel(reader: QRCodeReaderViewController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'TargetName' do
pod 'QRCodeReader.swift', '~> 6.0.0'
end
its give me this error on Xcode 7.3.1 swift 2.2;
fatal error: unexpectedly found nil while unwrapping an Optional value
when i compile and run my project give it this error, i don't write in viewdidload method for calling scan method, actually IBActionButton triggered for scan.
note: this error occurred in this week, 23-28 August 2016.
My app only supports Portrait mode but when the phone is put into landscape, the previewLayer is rotated
In QRCodeReaderViewController.orientationDidChanged(notification: NSNotification)
you call supportedInterfaceOrientations()
but because QRCodeReaderViewController doesn't declare override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
, the default results are returned (Portrait and Landscape).
Ive had to modify QRCodeReaderViewController and insert this to prevent rotation
override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return [.Portrait] }
Perhaps you could have a delegate call to get the correct supportedInterfaceOrientations or get them from the parent view controller?
I simply implemented QRCodeReader like you did in the example but it seems to don't scan others types of bar code. I initialised the view controller with EAN13 as metadata object type and it doesn't scan EAN 13 bar code. Otherwise it continues to scan QRCode.
class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
lazy var reader = QRCodeReaderViewController(metadataObjectTypes: [AVMetadataObjectTypeEAN13Code])
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func scanAction(sender: AnyObject) {
reader.delegate = self
reader.modalPresentationStyle = .FormSheet
presentViewController(reader, animated: true, completion: nil)
}
func reader(reader: QRCodeReaderViewController, didScanResult result: String) {
self.dismissViewControllerAnimated(true, completion: nil)
println(result)
}
func readerDidCancel(reader: QRCodeReaderViewController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
I would like to be able to differentiate between stop scanning and stop running.
Currently QRCodeReader
calls stopScanning
when a QR code is found. stopScanning
calls stopRunning
on the AVCaptureSession
which stops the video preview. This is undesirable for us as the 'QR screen' is not dismissed when a QR code is found and the sudden halting of the video preview is not a smooth user experience.
I can use the QRCodeReaderViewControllerDelegate in a UITableViewController? (Xcode 7 via cocoapods). I'm with this problem. Can anyone help me?
/Users/bhd/dev/IOS/FeedTableViewController.swift:8:7: Type 'FeedTableViewController' does not conform to protocol 'QRCodeReaderViewControllerDelegate'
My code
import UIKit
import AVFoundation
import Alamofire
import Haneke
import QRCodeReader
import SwiftyJSON
class FeedTableViewController: UITableViewController, QRCodeReaderViewControllerDelegate { //error here
egrep: /Pods/Target Support Files/QRCodeReader.swift: Is a directory
WARNING
Version: fc62c9e
The front facing camera on my iPhone 6 or new iPad Air can't seem to focus in to scan a QR Code or Code 39. It looks like the image is reversed when scanning the code39. Also it would be nice if there was a separate branch for XCode 6 and Swift 1.2.
dyld: Symbol not found: _AVCaptureDeviceTypeBuiltInWideAngleCamera
Referenced from: /var/containers/Bundle/Application/DDAF584C-7F2E-4C27-8AA6-8E162CFCAA91/QRCodeReader.swift.app/QRCodeReader.swift
Expected in: /System/Library/Frameworks/AVFoundation.framework/AVFoundation
in /var/containers/Bundle/Application/DDAF584C-7F2E-4C27-8AA6-8E162CFCAA91/QRCodeReader.swift.app/QRCodeReader.swift
(lldb)
Thread 1 : Signal SIGABRT
i run in iphone5C
Hi
i getting a gab in the middle off my tabbar after succesfull scanning a Ticket, if i press on the screen and wait for a few second i get my tabbar button back but with the text notification instead of "scanner"
Thanxz
Hi
I'm using this great scan tool to implement my app. very nice and fast.
no problem if I use iPhone 5s to scan QR code.
but once I use iPhone 6 to scan, the API of QRCodeReader.isAvailable() returns false. could you tell me why? thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.