I have a react native app where I am using RNCAsyncStorage
npm module for simple data persistence. How ever, my iOS
version of the app ships with a share extension, and this share extensions needs to access one of my stored data strings.
So in short, I want to use RNCAynscStorage
from swift native code to get the data which was stored from my react native code.
Before even trying to implement the module I asked RNC and they replied:
This is possible but requires some knowledge of how native modules work in general. I'm not sure how future-proof this is with regards to the upcoming refactoring work in React Native but this is how you could access it today:
// First, get the RNCAsyncStorage instance from the bridge
RNCAsyncStorage *asyncStorage = [bridge moduleForClass:[RNCAsyncStorage class]];
// Then call the getter:
[asyncStorage multiGet:@[@"count"]] callback:^(NSArray *response){
NSObject *count = response[0];
if ([count isKindOfClass:[NSError class]]) {
// Failed to get count
return;
}
// Use count here
}];
However, My extension is written in swift, and I am not sure how this would look when converted to swift.
First I followed a guide to make the react bridge module accessible in swift code, this is how my brinding looks:
I also tried to convert the objecttive-C example to seift, but this is not working as you can see.
I am not sure if this is because the module is not exposed/imported correctly, or simply if the swift conversion is wrong. but both bridge
and RNCAsyncStorage
is unresolved.