【问题标题】:null is not an object when calling react-native camera roll调用 react-native 相机胶卷时 null 不是对象
【发布时间】:2021-04-04 11:11:54
【问题描述】:

我正在使用 @react-native-community/cameraroll 库从相机胶卷上传视频。为此,我使用了 getPhotos 函数。但是,使用此函数会导致以下错误:

null is not an object (evaluating '_nativeInterface.default.getPhotos')

我调用getPhotos函数如下:

<Pressable onPress={() => {
          CameraRoll.getPhotos({first:10});
          }}
        style={({ pressed }) => [{
            backgroundColor: pressed ? 'white' : '#03befc'
        },
    styles.upload]}>
            <Text style={styles.uploadText}>Upload Video</Text></Pressable>

像我在 Pressable 组件的 onPress 事件中那样调用相机胶卷有什么问题,它给了我我提到的错误?

是的,我已经添加了键和字符串

<key>NSPhotoLibraryUsageDescription</key>
    <string>Our application needs permission to write photos...</string>
  <key>NSPhotoLibraryAddUsageDescription</key>
  <string>Our application needs permission to write photos...</string>

但我仍然收到错误消息。

【问题讨论】:

  • 你的设备是什么?
  • iPhone 11 模拟器
  • 你授权了吗?
  • 如何给它权限?
  • Info.plist 文件中

标签: react-native camera-roll


【解决方案1】:

我认为问题在于 js 上下文而不是代码。尝试在函数调用前添加 return,它可能会解决问题。

<Pressable onPress={() => {
         return CameraRoll.getPhotos({first:10});
          }}
        style={({ pressed }) => [{
            backgroundColor: pressed ? 'white' : '#03befc'
        },
    styles.upload]}>
            <Text style={styles.uploadText}>Upload Video</Text></Pressable>

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 2019-01-23
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多