Skip to content
ivan baktsheev edited this page Jul 16, 2016 · 2 revisions

Suites is supported for iOS/macOS platforms and Android platform

iOS/macOS

Documentation: iOS/macOS

This SO link contains detailed information how to setup iOS/macOS suite. Here is copy for your convenience:

  1. Open your main app target > Capabilities > App Groups set to on
  2. Add a new app group and make sure it is ticked (e.g. group.com.seligmanventures.LightAlarmFree)
  3. Open your watch target (the one with Capabilities tab) > App Groups set to on
  4. 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)
  5. 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];
  1. 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

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 ()
Clone this wiki locally