1

I have checked this & this and also other questions related to InAppSettingsKit, but couldn't reach to the solution.
I have downloaded LinPhone in which InAppSettingsKit is used for setting. Now, my requirement is I have to change the settings for only one particular case after login and it will be as it is for all the other cases.
Please guide me, how can I change settings for that one case and where?

Community
  • 1
  • 1
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39

1 Answers1

0

Here is a brief example:

// The name of the settings file, currently this plugin use the InAppSettings.bundle
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"InAppSettings" ofType:@"bundle"];
if(!settingsBundle) {
    NSLog(@"Could not find Settings.bundle");
    return;
}

NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root~iphone.inApp.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) {
        [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
    }
}

[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
[defaultsToRegister release];
[[NSUserDefaults standardUserDefaults] synchronize];

So this you can place it in your AppDelegate on lunch to get the settings. And then you can change a value associated with a key using NSUserDefaults

Example of retrieve:

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    CGFloat fontSize = 15;

    if(standardUserDefaults){
        fontSize = (CGFloat)[[standardUserDefaults objectForKey:@"fontSize"] floatValue];
        if(fontSize == 0)
            fontSize = 15;
    } 

Notify Controller on Settings Change

To see if some settings modified put this in your viewDidLoad of the Controller that you want to be notified:

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
           selector:@selector(defaultsChanged:)
               name:NSUserDefaultsDidChangeNotification
             object:nil];

And you have only to implement the function defaultsChanged.

Dimitris Bouzikas
  • 4,461
  • 3
  • 25
  • 33
  • Let me know if you want any further help. – Dimitris Bouzikas Feb 20 '14 at 12:54
  • @PiyushDubey Does my answer help you? You didn't add a comment or accept it, although this is the way which this plugin works. In this way you don't help SO's users, you know that i thought. – Dimitris Bouzikas Feb 22 '14 at 21:07
  • well, if the answer had helped me, then I would have accepted. I had explained you in chat about the issue and I am still working on the problem. I really appreciate your answer, but it didn't work for me and I am totally aware about SO users and to help them. You can't force to accept your answer unless it had help you. – Piyush Dubey Feb 24 '14 at 07:08