ios – iPhone 15 Professional Max Digital camera Ignores deviceId and Switches Between Lenses Robotically in React Apps

0
18
ios – iPhone 15 Professional Max Digital camera Ignores deviceId and Switches Between Lenses Robotically in React Apps


I’m constructing an internet app that makes use of the digital camera for doc scanning and have seen unusual habits on the iPhone 15 Professional Max. The telephone appears to:
1. Choose a default digital camera (doubtless the primary wide-angle lens).
2. Robotically change to a wider digital camera lens when specializing in an object.

Even after I explicitly present a deviceId within the videoConstraints, this habits persists. Altering the deviceId dynamically additionally doesn’t work—the digital camera defaults to the identical lens and continues to modify mechanically throughout use.

This leads to noticeable flickering because of the abrupt change in decision and discipline of view.

I’ve examined this in a React surroundings with each react-webcam and react-camera-pro, and the habits is constant.

you possibly can take a look at this in each demo apps:
1 – react-camera-pro
2 – react-webcam

Right here’s a simplified model of my setup:

import React, { useState, useEffect, useCallback } from 'react';
import Webcam from 'react-webcam';

const CameraComponent = () => {
  const [selectedDeviceId, setSelectedDeviceId] = useState();

  const handleDevices = useCallback((gadgets: MediaDeviceInfo[]) => {
    const videoDevices = gadgets.filter(({ form }) => form === 'videoinput');
    if (videoDevices.size > 0) {
      setSelectedDeviceId(videoDevices[0].deviceId); // Explicitly set the primary system
    }
  }, []);

  useEffect(() => {
    navigator.mediaDevices.enumerateDevices().then(handleDevices);
  }, [handleDevices]);

  return (
    
  );
};

export default CameraComponent;

This habits doesn’t happen on Android or older iPhones with a single rear digital camera.

What I’ve Tried:

•   Explicitly setting the deviceId in videoConstraints.
•   Dynamically altering the deviceId in the course of the digital camera feed.
•   Utilizing totally different React libraries (react-webcam and react-camera-pro).

My Query:

1.  Why does iOS override the deviceId and change between cameras mechanically?
2.  Is there any approach to pressure iOS to stay to a particular lens with out computerized switching?
3.  How can I stop the flickering brought on by the lens change throughout scanning?

Any insights or workarounds could be appreciated!

LEAVE A REPLY

Please enter your comment!
Please enter your name here