yannickl / QRCodeReader.swift

Simple QRCode reader in Swift
MIT License
1.33k stars 330 forks source link

Camera is not display, but scan is work, case of custom interface #120

Closed purplecofe closed 6 years ago

purplecofe commented 7 years ago

update to swift 4 version before is work fine

but update to swift 4 version after is not work

how can i fix it?

source code here https://gist.github.com/purplecofe/c9ea540760a990bf5aeec62b4507bee8

thanks for your help

lhchome commented 7 years ago

me too !

yannickl commented 7 years ago

You have to keep a reference to the QRCodeReader and add its previous layer by yourself in your view:

Jackhammer42 commented 7 years ago

I am seeing this behavior too. sometimes. for now, i was not able to reproduce it reliably.

BUT: I am using the code from the example project to instantiate the QRCodeReaderViewController from the pod files:

lazy var reader: QRCodeReader = QRCodeReader()
    lazy var readerVC: QRCodeReaderViewController = {
        let builder = QRCodeReaderViewControllerBuilder {
            $0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: .back)
            $0.showTorchButton = true
        }

        return QRCodeReaderViewController(builder: builder)
    }()

As far as I understand in this 'standard' ViewController the proposed fix for the behavior is already included, right?

I am using Xcode 9,swift 4 and QRCodeReader 8.0.3 . My test device is a iphone 6s plus running ios 9.3.5.

I see this too, on my iphone SE running ios 11

lai3d commented 6 years ago

Me too!

kangert commented 6 years ago

The same problem. An unmodified code, freshly downloaded from here. Cannot reproduce it reliably, but it occurs in about 20% of the app's starts. The app has to be killed to get an other attempt (cancel button will not help).

Tested on iPhone 6s (iOS 11) and iPhone 4s (iOS 9), Xcode 9.1.

kangert commented 6 years ago

Maybe it's coincidence, but it seems it happens mainly when the device is connected to Xcode. Can anyone confirm this observation?

yannickl commented 6 years ago

To be sure, the issue occurs when your are using the provided view controller or in the example project with the embedded view?

Is it related to #125?

kangert commented 6 years ago

1) Example project.

2) Hard to say. I'm unable to reproduce it in preview mode. However, if the "modal mode" is stuck in the black screen (black screen with icons and the rectangle), the preview mode works just fine along with it. There is also no info about scanner behavior in #125. Here, the scanner works ok, only the "live view" does not work, so you have to scan it blindly. This state is permanent for the session (cancel button or scanned QR code does not change the situation, only hard restart of the app - the app has to be killed or redeployed).

Jackhammer42 commented 6 years ago

In QRCodeReader.swift/Sources/QRCodeReaderView.swift I changed line 74 from private weak var reader: QRCodeReader? to var reader: QRCodeReader?. Since that change, everything works fine (aka i was not able to reproduce the described behavior anymore).

yannickl commented 6 years ago

@Jackhammer42 so the issue came from the fact the reader var is weak?

I'll investigate that, because I don't know why it happens.

Jackhammer42 commented 6 years ago

yes, indeed.

rustydr34m commented 6 years ago

image uploaded from ios

I have the same problem. Did you find a solution?

rustydr34m commented 6 years ago

I'dont know why but when set readerVC in viewDidAppear it's stable. I have done hundreds of tests today and it never happened. Any ideas?

override func viewDidAppear(_ animated: Bool) {

    readerVC = {
        let builder = QRCodeReaderViewControllerBuilder {
            $0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: .back)
            $0.showTorchButton = true

        }

        return QRCodeReaderViewController(builder: builder)
    }()
}
yannickl commented 6 years ago

@rustydr34m the last release don't fix your issue?

You still have to init the reader in the viewDidAppear?

rustydr34m commented 6 years ago

@yannickl private weak var reader: QRCodeReader? to private var reader: QRCodeReader? not fix the problem,

But when init the reader in the viewDidAppear (reader still private weak var reader: QRCodeReader?) problem solved for me. But I don't know why.

ruoyuruoshui commented 6 years ago

@yannickl previewLayer is initial twice when i debug

If a property marked with the lazy modifier is accessed by multiple threads simultaneously and the property has not yet been initialized, there is no guarantee that the property will be initialized only once.

yannickl commented 6 years ago

@ruoyuruoshui thank you for pointing me this point because I was sure it was atomic. I'll investigate that.

vcsabi commented 6 years ago

Still have this issue any news about this? I would really want to use it!

yannickl commented 6 years ago

@vcsabi is the issue still there with the v8.1.0?

vcsabi commented 6 years ago

@yannickl Really appreciate your fast response, and yes with the latest version

rustydr34m commented 6 years ago

in iphonex does not work at all

sharadchauhan0504 commented 6 years ago

@rustydr34m Did you find any solution ? It's same for me also.

dollykosmos commented 5 years ago

Please provide solution for "Camera is not display, but scan is work, case of custom interface" in Xcode 10.1

RexNexstream commented 5 years ago

Have the same problem

sedoyjan commented 5 years ago

Have the same problem

And me

sedoyjan commented 5 years ago

@yannickl Please provide solution for "Camera is not display, but scan is work, case of custom interface"