1

I can't find any tutorial or guide to show me how to save preferences with my Custom iOS 8 keyboard.

I have different skins and the user can cycle to all the skins. However if the user dismisses the keyboard then loads it back up, it will load the initial skin.

I know other keyboards have found a way to load Skins and remember which one was selected.

I also have 2 different layouts for my keyboard

QWERTY and DVORAK

I would like to also save that preference so user can change their selection when in my app.

Keyboard is done in Swift/Obj-C (not sure if that matters)

software is fun
  • 7,286
  • 18
  • 71
  • 129

2 Answers2

2

1. Create an app group for your host app and your custom keyboard

Select your host app's target, go to Capabilities, scroll to App Groups and add one by clicking on "+" sign. Type the name of your group.

Do the same with your keyboard's target but now simply add a group by ticking the recently added app group.

2. Now you can use NSUserDefaults to store & share data with your host app

Store data:

_userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.app-group-name"];
[_userDefaults setObject:@"theme-dark" forKey:@"KeyboardTheme"]; // save data

Restore data:

_userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.app-group-name"];
_theme = [_userDefaults objectForKey:@"KeyboardTheme"];
if ([theme isEqualToString:@"theme-dark"])
{
    ...
}

- Use constants & NS_ENUM instead of comparing strings.

- Full access has to be activated.

Apple Resources: head for “Sharing Data with Your Containing App“

Duc
  • 650
  • 5
  • 10
0

I know I need to use NSUserDefaults but not sure how to implement it.

software is fun
  • 7,286
  • 18
  • 71
  • 129