简体   繁体   English

next.js中二维码扫描器(手机)的实现方法

[英]How to implement qr code scanner(mobile) in next.js

I am building a website with scanning qr code.我正在建立一个扫描二维码的网站。 This works fine on desktop but not working on mobile.这在桌面上工作正常但在移动设备上不起作用。 In Reactjs, this works with secure connection.在 Reactjs 中,这适用于安全连接。 But in Nextjs, this does not work with secure connection.但是在 Nextjs 中,这不适用于安全连接。 I run custom server in Nextjs.我在 Nextjs 中运行自定义服务器。

https://dev.to/nakib/using-https-on-next.js-local-development-server-bcd https://dev.to/nakib/using-https-on-next.js-local-development-server-bcd

This is my code.这是我的代码。

import React, { useState } from 'react';
import { QrReader } from 'react-qr-reader';

const Home = (props) => {
    const [data, setData] = useState('No result');

    return (
        <>
            <QrReader
                onResult={(result, error) => {
                    if (!!result) {
                        setData(result?.text);
                    }

                    if (!!error) {
                        console.info(error);
                    }
                }}
                style={{ width: '100%' }}
            />
            <p>{data}</p>
        </>
    );
};
export default Home;

This is error from mobile chrome inspector.这是来自移动 chrome 检查器的错误。 error console错误控制台

It's like your browser is not supported.好像不支持你的浏览器。

https://github.com/react-qr-reader/react-qr-reader#browser-support https://github.com/react-qr-reader/react-qr-reader#browser-support

Try this:尝试这个:

Browser Support浏览器支持

The browser layer is using the MediaDevices web API which is not supported by older browsers.浏览器层使用的是MediaDevices web API,旧版浏览器不支持。

You can use external polyfills like WebRTC adapter to increase browser compatibility.您可以使用WebRTC 适配器等外部 polyfill 来提高浏览器兼容性。

Also, note that the library is using the TypedArray ( Int32Array , Uint8ClampedArray , etc.) which are not available in older browsers (eg Android 4 default browser).另请注意,该库使用的是TypedArrayInt32ArrayUint8ClampedArray等),这在旧浏览器(例如 Android 4 默认浏览器)中不可用。

You can use core-js to add support to these browsers.您可以使用core-js添加对这些浏览器的支持。

In the PDF 417 decoder recent addition, the library now makes use of the new BigInt type, which is not supported by all browsers as well.在最近添加的 PDF 417 解码器中,该库现在使用新的BigInt类型,并非所有浏览器都支持该类型。 There's no way to polyfill that and ponyfill libraries are way to big , but even if PDF 417 decoding relies on BigInt the rest of the library shall work ok in browsers that doesn't support it.没有办法 polyfill 和 ponyfill 库是大的方式,但即使 PDF 417 解码依赖于BigInt ,库的 rest 在不支持它的浏览器中也可以正常工作。

There's no polyfills for BigInt in the way it's coded in here. BigInt在此处的编码方式中没有 polyfill。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM