apla / me.apla.cordova.app-preferences

App preferences plugin for cordova
Apache License 2.0
201 stars 209 forks source link

iOS use: [NSUserDefaults initWithSuiteName:@"<configurable_name"> #34

Closed weiner closed 8 years ago

weiner commented 9 years ago

Hi,

I would love to have the option to use this module in combination with a iOS Extension. To share NSUserDefaults between the App and a Extenion you need to use the NSUserDefaults initWithSuiteName.

https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/ NSUserDefaults_Class/index.html#//apple_ref/occ/instm/NSUserDefaults/initWithSuiteName:

psaitu commented 9 years ago

This is quite easy to do.. all you have to do is change this line

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

to

NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.company.appname"];

in AppPreferences.m

It would be great to have it implemented by default but for those in need of it right now you can do it yourself by changing that one line. I think it appears in 3 different places in the same file.

apla commented 9 years ago

just got a clever idea how to implement this.

please checkout latest version

how to use:

var suitePrefs = plugins.appPreferences.iosSuite ("suiteName");
suitePrefs.fetch (...);
suitePrefs.store (...);
apla commented 8 years ago

No response