似乎可以AsyncStorage
从Android(本机)访问;但我仍在努力完成这项工作。
在我的 React Native 应用程序中,我有类似的东西:
店铺
const config = {
...
}
export const reducers = {
...
user: user
}
let rootReducer = combineReducers(reducers)
let reducer = persistReducer(config, rootReducer)
用户减速器
export class Actions {
...
}
const initialState = {
first_name: : null,
last_name: : null,
email: null,
addresses: [
{ ... }
]
}
}
}
export const reducer = (state = initialState, action) => {
switch (action.type) {
...
}
}
从商店获取用户
const user = store.getState().user
console.log(user.first_name) // Steve
...
现在,当我尝试从 Android 获取同一个用户时,问题就开始了,在我所有沮丧的尝试中,这就是我所拥有的:
try {
readableDatabase = ReactDatabaseSupplier.getInstance(getReactApplicationContext()).getReadableDatabase();
catalystLocalStorage = readableDatabase.query("catalystLocalStorage", new String[]{"value"}, "key = ?", new String[] { "full_name" }, null, null, null);
String[] names = catalystLocalStorage.getColumnNames();
if (catalystLocalStorage.moveToFirst()) {
final String value = catalystLocalStorage.getString(catalystLocalStorage.getColumnIndex("value"));
Log.d(TAG, value);
}
} finally {
if (catalystLocalStorage != null) {
catalystLocalStorage.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
}
由于 User 它是一个对象,我不知道这是否是获取 的正确方法'first_name'
,我尝试了 get'user'
但没有奏效。
我开始认为我应该在我知道我的数据结构的地方使用react-native-sqlite-storage,但我不知道我是否能够在 Android 上访问该数据库。
PS:我不想AsyncStorage
访问SharedPreferences
库版本
react-native: 0.48.4
redux: 3.7.2
redux-persist: 5.4.0
一些没用的问题