RN 链接原生依赖项目RCTCameraRoll

使用react-native init <projectName> 创建的项目,如果要使用到原生代码的部分,需要集成原生依赖项目;
如:CameraRoll 依赖的RCTCameraRoll;
步骤:
1、如果要在 iOS 上使用这个模块,我们首先要链接 RCTCameraRoll 库。进入到工程项目中的 node_module/react-native/Libraries/CameraRoll

image.png

2、把 RCTCameraRoll.xcodeproj 添加到在项目工程的 Liberaries 文件夹下


image.png

3、在 General -> Linked Frameworks and Libraries 里添加 libRCTCameraRoll.a


image.png

4、info.plist 中添加NSPhotoLibraryUsageDescription 和 NSPhotoLibraryAddUsageDescription

注意事项:iOS在模拟器上运行,可能无data值返回,请设置groupTypes为All,此值默认为SavedPhotos;

CameraRoll.getPhotos({
      first : 20,
      groupTypes: 'All',
      assetType: 'Photos',
      }).then(data => {
        this.setState({photoSource : {uri : data.edges[3].node.image.uri}});
      }).catch((error) => {
        alert(error);
      });
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。