I want to store a JSON object using Async Storage for my react-native app in android and iOS. I stringify the object and store it using Async Storage as it can only store strings. The app works fine in android but throws an error in iOS. The error is as follows:
Error: {
key = "";
message = "Invalid key - must be at least one character. Key: ";
}
RCTMakeAndLogError
RCTUtils.m:394
RCTErrorForKey
-[RCTAsyncLocalStorage _writeEntry:changedManifest:]
-[RCTAsyncLocalStorage multiSet:callback:]
__invoking___
-[NSInvocation invoke]
-[NSInvocation invokeWithTarget:]
-[RCTModuleMethod invokeWithBridge:module:arguments:]
facebook::react::RCTNativeModule::invokeInner(unsigned int, folly::dynamic const&&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_queue_serial_drain
_dispatch_queue_invoke
_dispatch_queue_override_invoke
_dispatch_root_queue_drain
_dispatch_worker_thread3
_pthread_wqthread
start_wqthread
My search led me to the iOS implementation of Async Storage for react-native here but I have no knowledge about Objective-C or Swift. Would be grateful if someone can help me out here. Thanks!
UPDATE
I use AsyncStorage to store the values in a JS file.
In my case, this issue occurs because I initialized the storage variables in the constants file with an empty string ("").
Now referring to the iOS implementation of AsyncStorage we can see that the function which emits the error message, accepts a string value of NSString Object and it requires that the string must have a length greater than 1. As an empty string will have a length 0, this error occurs.
So initialize the variables with any string but an empty one.
Thanks everyone for taking the time to view this error.