ios - 世博会 React Native 应用程序。使用 expo-secure-store 方法时出错 [该方法或属性 SecureStore.setItemAsync 在 ios 上不可用]

标签 ios reactjs react-native mobile expo

我已按照 expo 文档将此库包含到我的 expo 管理的 React Native 应用程序中。 SecureStore

我正在使用:

  • 世博会:44.0.5
  • react 原生:0.64.3(SDK 44)
  • 展览安全商店:11.1.0
  • expo-dev-client:0.8.6
  • react 和 react -dom 18.0.0
  • typescript

在我的 App.tsx 中:

import 'expo-dev-client'
import { deleteValueFor, getValueFor, save } from './src/core/infrastructure/storage/secureStore'
import { REFRESH_TOKEN } from './src/core/infrastructure/config/constants'
....

export default function App(): JSX.Element | null {
  ....

  useEffect(() => {
    ;(async () => {
     try {
      const refreshToken = await getValueFor(REFRESH_TOKEN)
      ...
      // things I do whit refreshToken
      ...
     } catch (e) {
      console.warn(e)
     }
    })()
   }, [])

   const login = async (authUser: AuthUser) => {
     const { token, refreshToken, user } = authUser

     if (!user) {
      throw 'Error al obtener los datos del usuario desde el context'
     }

     setToken(token)
     save({ key: REFRESH_TOKEN, value: refreshToken }) // <---- The error occurs here
   }
}

在 secureStore.ts 中

import * as SecureStore from 'expo-secure-store'

export async function save({ key, value }: { key: string; value: string }): Promise<void> {
 await SecureStore.setItemAsync(key, value)
}

export async function getValueFor(key: string): Promise<string | null> {
  try {
   return await SecureStore.getItemAsync(key)
  } catch (error) {
   return null
  }
}

export async function deleteValueFor(key: string): Promise<void> {
  await SecureStore.deleteItemAsync(key)
}

export async function checkAvailability(): Promise<boolean> {
  return SecureStore.isAvailableAsync()
}

我执行此命令以在模拟器中运行应用程序:

expo start --dev-client --ios

应用程序在模拟器中运行良好,没有错误。在我填写登录凭据并按下登录按钮后,这是我收到的错误消息:

[Unhandled promise rejection: Error: The method or property SecureStore.setItemAsync is not available on ios, are you sure you've linked all the native dependencies properly?]
at http://192.168.1.3:8082/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:111339:321 in _createSuperInternal
at node_modules/expo-modules-core/build/errors/CodedError.js:10:8 in constructor
at http://192.168.1.3:8082/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:111384:321 in _createSuperInternal
at node_modules/expo-modules-core/build/errors/UnavailabilityError.js:9:42 in constructor
at node_modules/expo-secure-store/build/SecureStore.js:103:14 in setItemAsync
at node_modules/expo-secure-store/build/SecureStore.js:97:7 in setItemAsync
at src/core/infrastructure/storage/secureStore.ts:4:8 in save
at src/core/infrastructure/storage/secureStore.ts:3:7 in save
at App.tsx:87:4 in login

我不知道出了什么问题。请帮忙。

最佳答案

如果有人正在研究类似的问题。

根据这个问题 https://github.com/expo/expo/issues/16906

由于我正在使用 expo-dev-client lib 来生成新的工件,因此我必须重建我的应用程序。之后,我可以使用 expo-secure-store 函数保存我的 token ,没有任何问题。

关于ios - 世博会 React Native 应用程序。使用 expo-secure-store 方法时出错 [该方法或属性 SecureStore.setItemAsync 在 ios 上不可用],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73142462/

相关文章:

ios - viewDidLoad() 在 segue 之后没有运行

javascript - SyntaxError - node_modules/react-native/Libraries/polyfills/error-guard.js : Missing semicolon. (14:4) 在 react 原生库中运行 jest

reactjs - npm uninstall -g create-react-app 和 yarn 全局删除 create-react-app 不起作用

javascript - react native 渐变按钮

javascript - 无法从 componentDidMount 调用函数

javascript - ScrollView 不会在 android 上滚动

android - react-native-keyboard-aware-scroll-view 中平台之间的不同行为

ios - 重新加载 UITableView 数据后,indexPathForCell 返回 null

iphone - iPad 和 iPhone 的不同布局

ios - iPhone来电查看类?