我正在创建一个反应本地iOS应用程序,而不是使用世博。我安装了AsyncStorage @react-native-async-storage/async-storage并在我的应用程序中使用它,如下面的代码所示。
问题是我得到了下面的错误消息。我已经尝试通过以下步骤来解决问题,但是错误仍然存在。有人能建议如何修正这个错误吗?
我的代码:
import AsyncStorage from '@react-native-async-storage/async-storage'
const authenticate = (token) => {
setAuthToken(token)
AsyncStorage.setItem('token', token)
}我为解决错误而采取的步骤(都不成功):
npm start --reset-cachepod install错误消息:
错误:@RNC/ AsyncStorage : NativeModule: AsyncStorage为null。要解决此问题,请尝试以下步骤: ·重建并重新启动应用程序。·运行带有
--reset-cache标志的包装机。·如果您在iOS上使用iOS,请在ios目录中运行pod install,然后重新构建并重新运行该应用程序。·如果在使用Jest进行测试时发生这种情况,请查看文档如何将AsyncStorage与其集成:https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
发布于 2022-05-17 21:44:49
当库未正确链接或自动链接无法工作时,通常会发生此错误。尝试按解释的这里那样手动链接库。
react-native link @react-native-async-storage/async-storage
https://stackoverflow.com/questions/72280617
复制相似问题