react-native-ios-settings-bundle
react-native-ios-settings-bundle copied to clipboard
value is empty or the key is not defined
after i create my Setting.Bundle:
and set this code lines:
RNIosSettingsBundle.get('url_reference',(err,value)=>{ console.log('sucesso ===',value); console.log('errooooo ======',err); })
I got this message:

Info project:
- "react": "16.9.0",
- "react-native": "0.61.5",
- "react-native-ios-settings-bundle": "^1.2.2",
Is this issue is resolved? I am getting same issue for multi value default value is not getting.
Hello guys, I was using this lib today and I also came across this error. In the attempts here, I realized that if you insert a Default Value into an item, that lib cannot get the value. I created a group with 3 inputs, without the Default Value, and managed to get the values.

To solve this issue with this implementation .
Adding a function to registerDefaultsFromSettingsBundle and call this function on applicationDidFinishLaunching
My implementation:
AppDelegate.m
[...]
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if DEBUG
NSLog(@"Registering default values from Settings.bundle");
NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
[defs synchronize];
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
if(!settingsBundle)
{
NSLog(@"Could not find Settings.bundle");
}else{
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
for (NSDictionary *prefSpecification in preferences)
{
NSString *key = [prefSpecification objectForKey:@"Key"];
if (key)
{
// check if value readable in userDefaults
id currentObject = [defs objectForKey:key];
if (currentObject == nil)
{
// not readable: set value from Settings.bundle
id objectToSet = [prefSpecification objectForKey:@"DefaultValue"];
[defaultsToRegister setObject:objectToSet forKey:key];
NSLog(@"Setting object %@ for key %@", objectToSet, key);
}
else
{
// already readable: don't touch
NSLog(@"Key %@ is readable (value: %@), nothing written to defaults.", key, currentObject);
}
}
}
[defs registerDefaults:defaultsToRegister];
[defs synchronize];
}
#endif
[...]
Output log:
Registering default values from Settings.bundle Setting object 0 for key custom_endpoint_enabled Setting object QA for key environment_url
Maybe anyone wants to have a set method or asynchronous get method. See attached code below
Edit File: RNIosSettingsBundle.m
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getValByKey:(NSString *)key)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults objectForKey:key];
}
RCT_EXPORT_METHOD(setValByKey:(NSString *)key value:(NSString *)value)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:value forKey:key];
}
In the future, I will try to create a separate repo with the ability to listen to changes. If anyone needs it
Hello ,
Any update on the issue?
Can anyone help
Maybe anyone wants to have a set method or asynchronous get method. See attached code below
Edit File: RNIosSettingsBundle.m
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getValByKey:(NSString *)key) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; return [defaults objectForKey:key]; } RCT_EXPORT_METHOD(setValByKey:(NSString *)key value:(NSString *)value) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:value forKey:key]; }In the future, I will try to create a separate repo with the ability to listen to changes. If anyone needs it
Hello @qDanik,
Have you created the repo?