Working with Settings

PDF for offline use
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-03

Apple Watch apps can use the same Settings functionality as iOS apps - the settings user interface is displayed in the Apple Watch iPhone app but the values are accessible in both your iPhone app and also the watch extension.

The settings will be stored in a shared file location that is accessible to both the iOS app and the watch app extension, defined by an App Group. You should configure an App Group before adding the settings using the instructions below.

Add Settings in a Watch Solution

In the iPhone app in your solution (not the watch app or extension):

  1. Right-click Add > New File... and choose Settings.bundle (you cannot edit the name in the New File dialog):

  2. Change the name to Settings-Watch.bundle (select and type Command + R to rename):

  3. Add a new key ApplicationGroupContainerIdentifier to the Root.plist with the value set to the app group you've configured, (eg. group.com.xamarin.WatchSettings in the sample):

  4. Edit the Settings-Watch.bundle/Root.plist to contain the options you wish to use - the template file contains a group. textfield, toggle switch and slider by default (which you can delete and replace with your own settings):

Use Settings in the Watch App

To access the values selected by the user, create an NSUserDefaults instance using the app group and specifying NSUserDefaultsType.SuiteName:

NSUserDefaults shared = new NSUserDefaults(
    "group.com.xamarin.WatchSettings",
    NSUserDefaultsType.SuiteName);

var isEnabled = shared.BoolForKey ("enabled_preference");
var userName = shared.StringForKey ("name_preference");

Apple Watch App

Users will interact with the settings via the new Apple Watch app on their iPhone. This app allows the user to show/hide apps on the watch, and also edit the settings exposed using the Settings-Watch.bundle.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.