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

Iphone 8 IOS 15.1 Safari camera dont start

Open manze2709 opened this issue 4 years ago • 10 comments

Hello on my iphone 8 ios 15.2 the camera does not start when loading websites the camera only starts when I lock and unlock the iphone. I have the same problem with the example "https://nimiq.github.io/qr-scanner/demo/". I have granted the website access to the camera, in the address bar I see a red camera icon that is crossed out.

manze2709 avatar Oct 28 '21 15:10 manze2709

I ran into the same issue on an iPhone SE (2nd gen) on iOS 15.1.

If I had to make a guess this might be caused by the permission handling.

I'd help debug this but seeing I have no Mac I can't debug this in Safari.

RVxLab avatar Nov 05 '21 10:11 RVxLab

Same problem on iphone 12 & 13 with iOS 15.1 in Safari.

When I initialize the camera I setCamera() to environment. However camera does not show up. As a workaround I switch between user and environment on load which causes the camera to show.

swdee avatar Dec 01 '21 01:12 swdee

I've had some issues with switching cameras once the stream starts. Instead of switching cameras, I play, pause, then play the video on start. I agree that this seems like a permissions issue in Safari.

My app is built in React which is why I am using a ref here, but you could identify your video tag however you like.

<video
  ref={videoTag}
  onCanPlay={() => {
    const playPromise = videoTag.current.play();

    if (playPromise !== undefined) {
      playPromise
        .then(() => {
          videoTag.current.pause();
          videoTag.current.play();
        })
        .catch((error) => {
          console.error(error);
        });
    }
  }}
  muted
  autoPlay
  playsInline
  preload="none"
/>

david-buck avatar Dec 10 '21 23:12 david-buck

Hey I've had some issues on my Iphone 12 iOS 14.0 the camera is working but the scanner is giving timeout error, however the scanner is working fine on Android devices

AjjlalAhmed avatar Jan 10 '22 14:01 AjjlalAhmed

This is fixed now, see #125.

@AjjlalAhmed please test whether your issue still exists on the newest release. If it does, please open a new issue or see whether #142 describes the same issue as yours. I couldn't reproduce it on the iPhone I tested on.

danimoh avatar Feb 04 '22 11:02 danimoh

I still need to run my fix (above) to get the camera to start reliably

david-buck avatar Feb 05 '22 06:02 david-buck

@david-buck Thanks for the feedback. Do you only encounter issues when switching the camera (e.g. environment facing to user facing) or also on first start of the scanner? And you're using v1.4.0 of this lib now?

danimoh avatar Feb 05 '22 20:02 danimoh

This is just on initialisation, I handle the camera preference as a setting so it's not done live. And yes, using 1.4.0

It works slightly more reliably if I take out the onCanPlay function, but will still only work about a third of the time.

david-buck avatar Feb 06 '22 00:02 david-buck

@danimoh I faced the same problem using the latest version with iOS 14.7.

EDIT: It works on iOS 15.4.

Fabster1993 avatar Mar 17 '22 08:03 Fabster1993

I had a similiar problem. When starting the camera on safari (mac or ios), the video image doesn't show the camera image. If I change to another tab and back then it starts working. In my case this was being cause because I had a div element just above the video tag that would be added or remove from the dom depending if there was an error or not with the video stream. Either making sure the above element is always present or always absent solves the issue. This seems to be a safari bug (tested on 16.3 and 16.4)

fimdomeio avatar May 03 '23 11:05 fimdomeio