我以前在 android 中开发,我曾经使用 SharePreference 来存储用户令牌。对于 ios 和 android 有什么可用的 react native 吗?
原文由 PuskarShestha 发布,翻译遵循 CC BY-SA 4.0 许可协议
我以前在 android 中开发,我曾经使用 SharePreference 来存储用户令牌。对于 ios 和 android 有什么可用的 react native 吗?
原文由 PuskarShestha 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您使用 create-react-native-app
或 exp
,您可以使用 Expo.SecureStore
来存储您的令牌。
import {SecureStore} from 'expo';
await SecureStore.setItemAsync('secure_token','sahdkfjaskdflas$%^&');
const token = await SecureStore.getItemAsync('secure_token');
console.log(token); // output: sahdkfjaskdflas$%^&
详情: https ://docs.expo.io/versions/latest/sdk/securestore
2020 年 12 月更新:
SecureStore模块现在变成了 expo-secure-store
import * as SecureStore from 'expo-secure-store';
await SecureStore.setItemAsync('secure_token','sahdkfjaskdflas$%^&');
const token = await SecureStore.getItemAsync('secure_token');
console.log(token); // output: sahdkfjaskdflas$%^&
原文由 Calvin W 发布,翻译遵循 CC BY-SA 4.0 许可协议
3 回答2.2k 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
1 回答798 阅读✓ 已解决
1 回答762 阅读✓ 已解决
1 回答823 阅读
1 回答991 阅读
1 回答888 阅读
您可能想使用 AsyncStorage
由于
AsyncStorage
现在已弃用。您可以使用 https://github.com/react-native-community/async-storage编辑:
对于所有指出 AsyncStorage 不安全的人,请参阅这篇 文章。