Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read from AsyncStorage in native code (Java, ObjectiveC/Swift)

Tags:

I have a background service I wrote in native (Java/ObjectiveC) that needs to access data from AsyncStorage in react native. I would like to know if there is an easy way to get this value directly from the native code instead of having to pass it manually through a bridge method.

Since this is a background service that runs even if the app is not running (in Android), it can not call the Javascript code when it needs this data. I could work around it (by setting it in native at the same time I set it in AsyncStorage) but it would be a lot more work.

like image 328
Hoffmann Avatar asked Aug 29 '17 11:08

Hoffmann


1 Answers

If you meant this one: https://reactnative.dev/docs/asyncstorage then, it's deprecated. I recommended react-native-default-preference: https://github.com/kevinresol/react-native-default-preference

On Android, it used SharedPreference, so if you use the same preference name. You should able to read it on Android native code

like image 143
Tran Quan Avatar answered Oct 17 '22 15:10

Tran Quan