IOS设备,Camera组件扫条形码无反应,偶发事件,微信版本7.0.12



  • import Taro, { Component } from '@tarojs/taro';
    import {
    Camera,
    View,
    Button
    } from '@tarojs/components';

    import './scanCode.less';

    export default class ScanCode extends Component {
    state = {
    showCamera: true
    };

    //用户拒绝使用摄像头时,展示提示信息
    handleScanError = e => {
    	const { type } = e;
    	if (type === 'error') {
    		this.setState({ showCamera: false });
    	}
    };
    
    //重新弹出摄像头授权页面
    handleReAuthCamera = () => {
    	const that = this;
    	Taro.openSetting({
    		success: res => {
    			res.authSetting = {
    				'scope.camera': true
    			};
    		}
    	}).then(() => that.setState({ showCamera: true }));
    };
    
    handleScanCode = e => {
    	const {
    		detail: { result }
    	} = e;
    
    	console.log('eee===>', e);
    };
    
    render() {
    	const { showCamera } = this.state;
    	return (
    		<View className="scan-view">
    			<View className="scan-border">
    				{showCamera ? (
    					<Camera
    						className="scan-camera"
    						mode="scanCode"
    						onError={this.handleScanError}
    						onScanCode={this.handleScanCode}
    						frameSize="small"
    						resolution="high"
    					></Camera>
    				) : (
    					<View className="scan-reauth">
    						<Button type="primary" onClick={this.handleReAuthCamera} />
    					</View>
    				)}
    			</View>
    		</View>
    	);
    }
    

    }


登录后回复