-
Notifications
You must be signed in to change notification settings - Fork 209
Suites
ivan baktsheev edited this page Jul 16, 2016
·
2 revisions
Suites is supported for iOS/macOS platforms and Android platform
This SO link contains detailed information how to setup iOS/macOS suite. Here is copy for your convenience:
- Open your main app target > Capabilities > App Groups set to on
- Add a new app group and make sure it is ticked (e.g. group.com.seligmanventures.LightAlarmFree)
- Open your watch target (the one with Capabilities tab) > App Groups set to on
- Add a new app group and make sure it is ticked (e.g. group.com.seligmanventures.LightAlarmFree - but must be the same name as group above)
- Save data to the group as follows:
Javascript
var appPrefs = plugins.appPreferences;
var suitePrefs = appPrefs.suite("group.com.yourgroup");
suitePrefs.store ("alarmTime", "It worked!").then (…)
Swift
var defaults = NSUserDefaults(suiteName: "group.com.yourgroup")
defaults?.setObject("It worked!", forKey: "alarmTime")
defaults?.synchronize()
Obj-C
NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourgroup"];
[shared setObject:@"It worked!" forKey:@"alarmTime"];
[shared synchronize];
- Retrieve data from the group as follows:
var appPrefs = plugins.appPreferences;
var suitePrefs = appPrefs.suite("group.com.yourgroup");
suitePrefs.fetch ("alarmTime").then (…)
var defaults = NSUserDefaults(suiteName: "group.com.yourgroup")
defaults?.synchronize()
// Check for null value before setting
if let restoredValue = defaults!.stringForKey("alarmTime") {
myLabel.setText(restoredValue)
}
else {
myLabel.setText("Cannot find value")
}
NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourgroup"];
id value = [shared valueForKey:@"alarmTime"];
NSLog(@"%@",value);
Android platform has two different API calls to acquire preferences object.
- Default preference:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- Named preference:
public static final String PREF_FILE_NAME = "PrefFile";
SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
When you're asking for suite from app preferences plugin, you'll get a named shared preference.
Example:
var appPrefs = plugins.appPreferences;
var suitePrefs = appPrefs.suite("group.com.yourgroup");
suitePrefs.store ("alarmTime", "It worked!").then (…)