ngx-scanner icon indicating copy to clipboard operation
ngx-scanner copied to clipboard

Use in Cordova App on iOS

Open wstrik opened this issue 5 years ago • 11 comments

In relation to #167 and #210 I'm trying to get the zxing-js library working with Cordova on iOS. Thanks to the related issues, it is working on Android. I guess it's the same problem that was with Android. Which is it doesn't has permissions for the camera.

I have just a blank page with the plugin on it. I get the following error: ERROR: {"line":2,"column":28352,"sourceURL":"..../zxing-umd.js"} Which reads: throw new Error("Can't enumerate devices, method not supported."); As said, i think this is because of no camera permissions.

I tried installing the barcodescanner with no result.

wstrik avatar Jan 09 '20 08:01 wstrik

Seems like camera permissions problem, have you tried using anything like this?

odahcam avatar Jan 09 '20 20:01 odahcam

Yes, I've installed that plugin also.

So I installed and started the Barcodescanner plugin. Than it asks for the camera permission and the plugin works. After that I loaded the zxing library, but still the same error.

Also when I run navigator.mediaDevices.getUserMedia({ video: true }) it doesn't return anything.

wstrik avatar Jan 10 '20 07:01 wstrik

As this comment says, I think maybe cordova uses some web view implementation (obviously) and because of that the WebRTC API might not be available for Cordova on iOS. That seems like the same issue we have with PWAs at this moment.

odahcam avatar Jan 11 '20 20:01 odahcam

Hmm, thanks!

wstrik avatar Jan 14 '20 07:01 wstrik

Have you taken a look at React Native implementations?

odahcam avatar Jan 14 '20 11:01 odahcam

No. But I worked it out with the Cordova Barcodescanner plugin implemented in the hosted site. It only gets loaded when it's in the app. Otherswise it loads xzing.

wstrik avatar Jan 14 '20 12:01 wstrik

We're having the same problem. It's a known limitation because of missing WebRTC support in the WkWebView (hopefully this changes soon). Anyhow, there is cordova-plugin-iosrtc, which provides an implementation of WebRTC. We tried that out and only succeeded partially. The camera loads and is visible, but the scanSuccess (nor error) event aren't triggered.

pj035 avatar Jul 08 '20 13:07 pj035

@wstrik can you elaborate how you worked around this limitation and scan barcodes on iOS cordova?

capc0 avatar Sep 01 '20 08:09 capc0

@pj035 Did you work out how to use it together with the cordova-plugin-iosrtc to trigger the scanSuccess event? Or did you solve it in another way. Would be interested as I'm facing similar issues and haven't tried it yet

ninijay avatar Nov 18 '20 16:11 ninijay

@ninijay I was testing this for a customer app and due to time constraints I didn't follow it any further. We are now using one of the ionic plugins to scan QR codes. They are slower, but at least we can use them (no blame on ngx-scanner, but rather on Apple).

Sorry!

pj035 avatar Nov 19 '20 14:11 pj035

Just as an update, latest iOS version seem to support the WebRTC API needed for this component to work. I didn't test it yet, but it's good news already.

odahcam avatar Feb 09 '21 03:02 odahcam