gpt4 book ai didi

ios - 如何在 React Native 0.60+ 中添加原生模块?

转载 作者:行者123 更新时间:2023-12-01 19:39:02 31 4
gpt4 key购买 nike

我试图了解 React Native 0.60+ 中存在的自动链接与我们在之前的 React Native 版本中的自动/手动链接之间的区别。
当我添加 react-native-gesture-handlernpm i react-native-gesture-handler ,我的 Podfile 中没有添加任何行。所以当我做 pod install ,我假设手势处理程序模块未链接。但是,如果我像以前的 React Native 版本一样手动链接它,通过拖动 .xcodeproj文件到库等中,它会引发错误并告诉我取消链接。

我想知道的:

我对吗,自动链接的作用是将给定模块的一行添加到您的 Podfile 中,然后当您 pod install 时链接它?如果是这样,为什么当我做 npm i react-native-gesture-handler 时会这样?我的 Podfile 中没有添加任何内容?并且鉴于没有添加任何内容并且手动链接模块会引发错误,我应该如何链接模块?

最佳答案

当您创建一个新项目并且 react-native 版本 >=60 时,此行会自动添加到 pod 文件中( official site )

# example/ios/Podfile
require_relative '../../node_modules/@react-native-community/cli-platform-ios/native_modules'


这是脚本的路径,因此当您运行“pod install”时,它将检查所有库并安装所需的所有 pod 文件

因此,当您添加新库时,我的 Podfile 中不会添加任何行,但您必须运行“pod install”以便脚本文件可以运行并安装新的 pod 文件。

请不要使用 official site 中所述的手动链接。

This means that all libraries need to ship a Podspec either in the root of their folder or where the Xcode project is. Podspec references the native code that your library depends on.

The implementation ensures that a library is imported only once. If you need to have a custom pod directive then include it above the use_native_modules! function.



您必须执行 2 个步骤

1:添加库 “ yarn 添加 react 原生手势处理程序”

2:cd ios && pod 安装

关于ios - 如何在 React Native 0.60+ 中添加原生模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58034600/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com