• iOS 18과 watchOS 11 부터 iOS의 Live Activity가 자동으로 Apple Watch의 Smart Stack에 뜬다.
  • Review your Live Activity
    • 기본적으로는 앱의 이름과 compact leading, compact trailing 뷰가 뜬다.

      스크린샷 2024-07-06 오전 12.27.30.png

    • 모든 업데이트는 자동으로 전달된다.

    • 업데이트 얼럿이 뜰 때, 워치페이스 상태면 자동으로 스택이 뜬다.

      스크린샷 2024-07-06 오전 12.28.46.png

    • 포그라운드 상태였다면 compact 뷰들이 화면 아래에 뜨게 된다.

      스크린샷 2024-07-06 오전 12.30.03.png

    • 이를 탭하면 앱을 열 수 있는 버튼이 있는 전체 화면이 뜬다.

      스크린샷 2024-07-06 오전 12.30.39.png

    • compact 뷰들이 적절한 정보를 전달하는지 점검하라.

  • Customize for Apple Watch
    • supplementalActivityFamilies API를 통해서 smart stack을 지원하는 것을 나타낼 수 있다.

      • 다만 이렇게만 하면 기존에 락스크린용으로 디자인된 화면을 사용하기 때문에 올바르게 뜨지 않을 것이다.
      struct DeliveryLiveActivity: Widget {
          var body: some WidgetConfiguration {
              ActivityConfiguration(
                  for: DeliveryActivityAttributes.self
              ) { context in
                  DeliveryActivityContent(context: context)
              } dynamicIsland: { context in
      					// ...
              }
              .supplementalActivityFamilies([.small])
          }
      }
      

      스크린샷 2024-07-06 오전 12.34.12.png

    • activityFamily Environment 값을 사용해서 다른 레이아웃을 적용할 수 있다.

      struct DeliveryActivityContent: View {
          @Environment(\\.activityFamily) var activityFamily
          var context: ActivityViewContext<DeliveryActivityAttributes>
      
          var body: some View {
              switch activityFamily {
              case .small:
                  DeliverySmallContent(context: context)
              case .medium:
                  DeliveryMediumContent(context: context)
              @unknown default:
                  DeliveryMediumContent(context: context)
              }
          }
      }
      
    • 이 모든 것들은 당연히 프리뷰에서 확인이 가능하다.

    • 기본적으로는 iOS 앱을 열게 되지만 watchOS 타겟에 “Supports Launch for Live Activity Attribute Types” 키에 값들을 추가하면 된다.

      • 모든 타입의 Live Activity를 지원하고 싶으면 값을 비워놓으면 된다.
      • 특정한 것만 띄우게 하고 싶으면 ActivityAttributes를 채택한 타입을 명시하면 된다.
  • Keep it live
    • Update frequency
      • 기본적으로 watch와 자동으로 동기화 된다.
        • 별도 푸시 토큰이나 추가 코드는 필요없다.
      • 배터리 수명을 위해서 업데이트 동기화는 제한적으로 이뤄진다.
        • 제한치는 iOS와 비슷하다.
      • 푸시를 통해서 하고 있었다면 추가 작업은 필요없다.
        • 고빈도(high-frequency) 업데이트도 지원한다
      • 로컬 업데이트는 제한이 있다.
        • budget을 넘어가면 즉시 반영되지 않을 수 있다.
        • 다만 손목을 들어올리면 최신 정보를 즉시 가져온다.
    • Limited connectivity
      • 연결이 잘 되어 있다면(근처에 있거나 같은 Wi-Fi 망에 있으면) 다 잘 전달된다.
      • 연결이 제한적이면 Start, End, 얼럿 업데이트가 우선적으로 전달된다.
      • 시스템은 사용자에게 마지막으로 전달된 메시지를 띄워줌으로 최신 정보를 보고 있지 않다는 것을 인지하게 한다.
    • Always-On Display
      • 손목을 내려서 Always-On 모드로 가면 자동으로 컬러 스킴을 어둡게 바꾸고 저조도 모드로 들어간다.

      • 이 상태도 Environment를 사용해서 대응할 수 있다.

        struct DeliveryGauge: View {
            @Environment(\\.isLuminanceReduced) private var isLuminanceReduced
            var context: ActivityViewContext<DeliveryActivityAttributes>
        
            var body: some View {
                Gauge(value: context.state.progressPercent) {
                    GaugeLabel(context: context)
                }
                .tint(isLuminanceReduced ? .gaugeDim : .gauge)
            }
        }
        
      • 원하면 컬러 스킴을 고정할 수도 있다.

        • 안하면 자동으로 Always-On Display 모드에서 다크모드 적용이 된다.
        struct DeliveryActivityContent: View {
            @Environment(\\.activityFamily) var activityFamily
            var context: ActivityViewContext<DeliveryActivityAttributes>
        
            var body: some View {
                switch activityFamily {
                case .small:
                    DeliverySmallContent(context: context)
                        .preferredColorScheme(.light)
                case .medium:
                    DeliveryMediumContent(context: context)
                @unknown default:
                    DeliveryMediumContent(context: context)
                }
            }
        }