简体   繁体   English

Expo 相机的 takePictureAsync 不返回任何内容。 (承诺从未兑现)

[英]takePictureAsync of Expo's Camera returns nothing. (Promise never fulfilled)

I started using Camera from Expo for React Native ( https://docs.expo.io/versions/v35.0.0/sdk/camera/ )我开始使用来自 Expo 的Camera进行 React Native( https://docs.expo.io/versions/v35.0.0/sdk/camera/

I see camera window but when I call await this.camera.takePictureAsync();我看到相机 window 但是当我调用await this.camera.takePictureAsync(); the Promise is never finished and I get no output. Promise 从未完成,我没有得到 output。

My camera:我的照相机:

<Camera ref={(camera) => this.camera = camera}
  style={{flex: 1}}
  type={this.state.type}
>
  <Button onPress={() => this.snap()} title='SNAP'/>
</Camera>

Snap function:卡扣 function:

snap = async () => {
  if (this.camera) {
      console.log("SNAP!");
      let photo = await this.camera.takePictureAsync();
      console.log(photo);
  }
};

The SNAP! SNAP! is shown in console so there is no problem with camera itself.显示在控制台中,因此相机本身没有问题。 Second console.log is never called.第二个console.log永远不会被调用。

I am testing my app on Android 9 (Real device)我正在 Android 9(真实设备)上测试我的应用程序

EDIT: It is working on emulator, so there must be problem specifically with the real device编辑:它正在模拟器上工作,所以真实设备肯定有问题

Try to set useCamera2Api prop to true for Camera element.尝试将相机元素的 useCamera2Api 属性设置为 true。

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

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