Xamarin에서 watchOS 설정 작업

Apple Watch 앱은 iOS 앱과 동일한 설정 기능을 사용할 수 있습니다. 설정 사용자 인터페이스는 Apple Watch i전화 앱에 표시되지만 i전화 앱과 시계 확장 모두에서 값에 액세스할 수 있습니다.

Apple Watch apps can use the same Settings functionality as iOS apps

설정은 앱 그룹에서 정의한 iOS 앱과 조사식 앱 확장 모두에서 액세스할 수 있는 공유 파일 위치에 저장됩니다. 아래 지침을 사용하여 설정을 추가하기 전에 앱 그룹을 구성해야 합니다.

조사식 솔루션에서 설정 추가

솔루션의 i전화 앱에서(조사식 앱 또는 확장이 아님):

  1. 새 파일 추가 > 를 마우스 오른쪽 단추로 클릭하고 설정.bundle을 선택합니다(새 파일 대화 상자에서 이름을 편집할 수 없음).

    Add a new Settings Bundle

  2. 이름을 설정-Watch.bundle(이름을 바꿀 Command + R 선택 및 입력)으로 변경합니다.

    Rename the bundle

  3. 구성한 앱 그룹에 값이 설정된 Root.plist에 새 키를 ApplicationGroupContainerIdentifier추가합니다(예: 샘플에서). group.com.xamarin.WatchSettings

    Add a ApplicationGroupContainerIdentifier key to the Root.plist

  4. 사용하려는 옵션을 포함하도록 설정-Watch.bundle/Root.plist를 편집합니다. 템플릿 파일에 그룹이 포함되어 있습니다. textfield, 토글 스위치 및 슬라이더(삭제하고 사용자 고유의 설정으로 바꿀 수 있음)

Edit the Settings-Watch.bundle/Root.plist

조사식 앱에서 설정 사용

사용자가 선택한 값에 액세스하려면 앱 그룹을 사용하여 인스턴스를 NSUserDefaults 만들고 다음을 지정합니다 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 앱

The new Apple Watch app on the iPhone

사용자는 i전화 새 Apple Watch 앱을 통해 설정과 상호 작용합니다. 이 앱을 사용하면 사용자가 시계에 앱을 표시/숨길 수 있으며 설정-Watch.bundle를 사용하여 노출된 설정을 편집할 수도 있습니다.

Screenshot shows WatchKitSettings in the app.Screenshot shows WatchTodo in the app.