NSUserDefault only works once in a keyboard extension in iOS8

I have options that allow the user to select a background color Keyboardwith a keyboard extension using Xcode beta 1.

I can save and load from NSUserDefault. But only once. after I changed the value twice and tested with UITextField(Even iOS Built in App). It does not work and does not change the background color.

However, when I close the application and reopen it, this changed value works, and the background color changes.

Here is my code that saves the data in NSUserDefault.

self.defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.mycompany.keyboard"];

- (void)savePreferences
{
    [self.defaults setBool:self.redColorSwitch.on forKey:@"redColor"];

    [self.defaults synchronize];
}

and download code

self.defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.mycompany.keyboard"];

if([self.defaults boolForKey:@"redColor"])
    {
        self.myKeyboard.backgroundColor = [UIColor redColor];
    }

    else
    {
        self.myKeyboard.backgroundColor = [UIColor blackColor];
    }

Are there any errors in my codes?

+4
source share

Source: https://habr.com/ru/post/1545568/


All Articles