λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
🍎 iOS/WWDC

[iOS] WWDC23: Meet ActivityKit / Live Activity μ•Œμ•„λ³΄κΈ°

by Danna 2023. 10. 9.
728x90
728x90

WWDC23: Meet ActivityKit

https://developer.apple.com/documentation/ActivityKit
https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities

  • Live Activity 에 λŒ€ν•œ κ°œμš”
  • Live Activity 의 생λͺ…μ£ΌκΈ° (Life cycle)
  • Live Activity UI κ΅¬μΆ•ν•˜κΈ°

Live Acitvity overview

Live Activity λŠ” μ΄λ²€νŠΈλ‚˜ μž‘μ—… 진행 상황을 ν•œλˆˆμ— μ•Œμ•„λ³Ό 수 μžˆλŠ” 방법이닀.

  • 각각의 μ‹œμž‘κ³Ό 끝을 가지고 있고,
  • λ°±κ·ΈλΌμš΄λ“œ μ•± λŸ°νƒ€μž„μ—μ„œ μ‹€μ‹œκ°„ μ—…λ°μ΄νŠΈλ₯Ό μ œκ³΅ν•˜κ±°λ‚˜,
  • ν‘Έμ‹œ μ•Œλ¦Όμ„ μ‚¬μš©ν•΄μ„œ μ›κ²©μœΌλ‘œ μ œκ³΅ν•  μˆ˜λ„ μžˆλ‹€.

iPhone 14 Pro, Pro Max μ—μ„œλŠ” Dynamic Island λ₯Ό 톡해 Live Activity κ°€ ν‘œμ‹œλœλ‹€.

  • 앱이 λ°±κ·ΈλΌμš΄λ“œμ— μžˆμ„ λ•Œ μ‹œμŠ€ν…œ 전체에 Live Activity λ₯Ό ν‘œμ‹œν•˜κ³ ,
  • Live Activity λŠ” "compact" ν”„λ ˆμ  ν…Œμ΄μ…˜μ„ μ‚¬μš©ν•΄μ„œ λ Œλ”λ§λ˜κ³ , ν•œλ²ˆμ— μ΅œλŒ€ 2κ°œκ°€ ν‘œμ‹œλœλ‹€.
  • "minimal" μ‚¬μ΄μ¦ˆλ‘œ ν‘œμ‹œλ˜κ³ , 길게 λˆ„λ₯΄λ©΄ "expanded" ν”„λ ˆμ  ν…Œμ΄μ…˜μœΌλ‘œ λ³Ό 수 μžˆλ‹€.

Interactive Live Activities

iOS17 μ—μ„œλŠ” WidgetKit, SwiftUI λ₯Ό μ‚¬μš©ν•΄μ„œ λ²„νŠΌμ΄λ‚˜ 토글을 μΆ”κ°€ν•˜λŠ” λ“± Live Acitvity 에 μƒν˜Έμž‘μš© κΈ°λŠ₯을 μΆ”κ°€ν•  수 μžˆλ‹€.

overview

  • Live Activity λŠ” ActivityKit ν”„λ ˆμž„μ›Œν¬μ„ μ‚¬μš©ν•΄μ„œ 생λͺ…μ£ΌκΈ°λ₯Ό μš”μ²­, μ—…λ°μ΄νŠΈ 관리할 수 μžˆλ„λ‘ μ§€μ›λœλ‹€.
  • SwiftUI 와 WidgetKit 을 μ‚¬μš©ν•΄μ„œ μ„ μ–Έμ μœΌλ‘œ λ°°μΉ˜λœλ‹€.
  • 앱이 ν¬κ·ΈλΌμš΄λ“œ μƒνƒœμ— μžˆμ„ λ•Œ Live Activity λ₯Ό μš”μ²­ν•  수 있고, μ‚¬μš©μžμ˜ μ•‘μ…˜μ΄ μžˆλŠ” κ²½μš°μ—λ§Œ μš”μ²­ν•΄μ•Ό ν•œλ‹€.
    • Live Activity λŠ” μ•Œλ¦Όκ³Ό λΉ„μŠ·ν•˜κ²Œ μ‚¬μš©μžκ°€ μ‘°μ •ν•˜κ³ , μ•±μ—μ„œ μ‰½κ²Œ 끌 수 μžˆλ‹€.
  • 잠금 ν™”λ©΄κ³Ό λ‹€μ΄λ‚˜λ―Ή μ•„μΌλžœλ“œμ˜ μ„Έκ°œμ˜ ν”„λ ˆμ  ν…Œμ΄μ…˜μ„ μ§€μ›ν•΄μ•Όν•œλ‹€.
  • λ°±κ·ΈλΌμš΄λ“œ λŸ°νƒ€μž„ 외에도 ν‘Έμ‹œ μ•Œλ¦Όμ„ 톡해 μ›κ²©μœΌλ‘œ μ—…λ°μ΄νŠΈ ν•  수 μžˆλ‹€.

Lifecycle of Live Activities

  • Request : activity 에 μš”μ²­μ„ 보내 μ‹œμž‘ν•˜κΈ°
  • Update : 졜근 μ½˜ν…μΈ λ‘œ μ—…λ°μ΄νŠΈν•˜κΈ°
  • Observe activity state : λ³€ν™”λ˜λŠ” μƒνƒœλ₯Ό κ΄€μ°°ν•˜κΈ°
  • End : μž‘μ—… μ’…λ£Œμ‹œ activity 도 μ’…λ£Œν•˜κΈ°

Request

ν¬κ·ΈλΌμš΄λ“œ μƒνƒœμ˜ μ•±μ—μ„œ 초기 μ½˜ν…μΈ μ™€ ν•„μš”ν•œ activity request data λ₯Ό 갖도둝 κ΅¬μ„±ν•œλ‹€.

https://developer.apple.com/documentation/activitykit/activityattributes
ContentState λΌλŠ” μ΄λ„ˆνƒ€μž…μ΄ Live Activity 의 λ‹€μ΄λ‚˜λ―Ή μ½˜ν…μΈ λ₯Ό ν‘œμ‹œν•œλ‹€.

  • hero λΌλŠ” 정적 데이터 ν•˜λ‚˜λ₯Ό κ°–κ³  μžˆλŠ” AdventureAttributes
  • νžˆμ–΄λ‘œμ˜ HP λž‘ 이벀트 μ„€λͺ…에 λŒ€ν•œ ContentState λ₯Ό μ •μ˜ν•œλ‹€.
    • ν•΄λ‹Ή 속성듀이 λ³€κ²½λ˜λ©΄ live activity UI κ°€ μ—…λ°μ΄νŠΈλœλ‹€.

  • Content State 의 μ΄ˆκΈ°κ°’μ„ μ„€μ •ν•˜κ³ , ActivityContent λ₯Ό 생성해쀀닀.
    • staleDate λŠ” activity μ½˜ν…μΈ κ°€ λ³΄μ—¬μ£ΌλŠ” 데이터가 out of date 으둜 κ°„μ£Όλ˜λŠ” μ‹œκΈ°λ₯Ό μ‹œμŠ€ν…œμ— μ•Œλ¦΄ 수 μžˆλŠ” 값이닀.
    • relevenceScore λŠ” live activity κ°„ μš°μ„ μˆœμœ„λ₯Ό μ„€μ •ν•˜λŠ” 값이닀. λ‘κ°œ 이상 activity κ°€ λ³΄μ—¬μ§ˆλ•Œ μš°μ„ λ˜κ±°λ‚˜, 잠금 ν™”λ©΄μ—μ„œμ˜ λ™μž‘μ— μ‚¬μš©λœλ‹€.
  • ActivityAttributes, ActivityContent 와 push type 을 μ„€μ •ν•΄μ„œ request λ₯Ό 보낸닀.
    • push type 은 ν‘Έμ‹œλ₯Ό 톡해 동적 μ½˜ν…μΈ μ— λŒ€ν•œ μ—…λ°μ΄νŠΈλ₯Ό μˆ˜μ‹ ν•˜λŠ”μ§€ μ—¬λΆ€λ₯Ό λœ»ν•œλ‹€.
    • nil 둜 μ„€μ •ν•˜κ²Œ 되면 둜컬 μ—…λ°μ΄νŠΈλ§Œ 받을 수 μžˆμŒμ„ λœ»ν•œλ‹€.

Update

  • dynamic attirubtes λŠ” live activity λ₯Ό μ—…λ°μ΄νŠΈν•  μ‹œκΈ°λ₯Ό μ•Œλ €μ€€λ‹€.
  • 체λ ₯이 변경될 λ•Œ ContentState λ₯Ό μƒˆλ‘­κ²Œ λ§Œλ“€κ³ , Alert λ₯Ό μƒμ„±ν•˜κ³ , live activity 에 μ—…λ°μ΄νŠΈ API λ₯Ό ν˜ΈμΆœν•œλ‹€.

Observe activity state

  • live activity 의 생λͺ…μ£ΌκΈ° λ‚΄μ—μ„œλŠ” μ–Έμ œλ“ μ§€ Activity State λŠ” 변경될 수 μžˆλ‹€.
    • started, finished, dismissed, stale 4가지 μƒνƒœ
    • activityStateUpdates API λ₯Ό 톡해 μœ„μ˜ μƒνƒœλ“€μ„ κ΄€μ°°ν•΄μ„œ μ—…λ°μ΄νŠΈλ₯Ό λΉ„λ™κΈ°λ‘œ μˆ˜μ‹ ν•  수 μžˆλ‹€.

  • activityState API λ₯Ό ν†΅ν•΄μ„œλ„ λ™κΈ°μ μœΌλ‘œ μƒνƒœλ₯Ό 체크할 수 μžˆλ‹€.

End

  • live activity λ₯Ό μ’…λ£Œν•˜κΈ° μœ„ν•΄μ„œ 그에 λ§žλŠ” ContentState λ₯Ό μƒμ„±ν•˜κ³ , dismissalPolicy λ₯Ό μ§€μ •ν•΄μ„œ activity λ₯Ό μ’…λ£Œν•œλ‹€.

Building Live Activity UI

  • WidgetBundle 에 Live Activity 에 κ΄€ν•œ 섀정을 μΆ”κ°€ν•΄μ€€λ‹€.

  • μœ„μ ―κ³Ό λ™μΌν•˜κ²Œ WidgetConfiguration νƒ€μž…μ˜ body λ₯Ό μž‘μ„±ν•΄μ€€λ‹€.
  • ActivityConfiguration 객체λ₯Ό ν†΅ν•΄μ„œ Live Activity 의 μ½˜ν…μΈ μ— λŒ€ν•΄ μ„€μ •ν•  수 있고,
  • presentation ν΄λ‘œμ €λ§ˆλ‹€ 화면에 λ³΄μ—¬μ§ˆ UI λ₯Ό ꡬ성할 수 μžˆλ‹€.

Lock screen presentation

  • 첫번째 ν΄λ‘œμ €λŠ” 잠금 화면에 λŒ€ν•œ UI λ₯Ό μ§€μ •ν•œλ‹€.

 

Compact presentation

  • compact νƒ€μž…μ—μ„œλŠ” leading κ³Ό trailing μ˜μ—­μ„ λ”°λ‘œ μ„€μ •ν•  수 μžˆλ‹€.

 

Minimal presentation

  • μ—¬λŸ¬ (μ΅œλŒ€ λ‘κ°œ..) 앱이 Live Activity 에 λ„μ›Œμ§ˆ κ²½μš°μ—λŠ” minimal ν˜•νƒœλ‘œ λ„μ›Œμ§„λ‹€.
  • ν•˜λ‚˜λŠ” λ‹€μ΄λ‚˜λ―Ή μ•„μΌλžœλ“œμ˜ μ™Όμͺ½νŽΈμ— live activity κ°€ λ‚˜νƒ€λ‚˜κ³ , λ‹€λ₯Έ ν•˜λ‚˜λŠ” 였λ₯Έμͺ½μ— λΆ„λ¦¬λœ μ˜μ—­μœΌλ‘œ λ‚˜νƒ€λ‚œλ‹€.

 

 

Expand presentation

  • Live activity λ₯Ό κΎΉ λˆ„λ₯΄λ©΄ expand ν˜•νƒœλ‘œ λ³Ό 수 μžˆλŠ”λ°, 이 μ˜μ—­λ„ Leading, Trailing, Center, Bottom 으둜 λ‚˜λ‰˜μ–΄μ Έ μžˆλ‹€.
  • leading
  • trailing
  • bottom

Designing Live Activity UI

  • ν•„μˆ˜μ μΈ μ½˜ν…μΈ λ₯Ό λ‹΄κ³ , μ‹¬ν”Œν•˜κ²Œ λ””μžμΈν•˜λŠ” 것이 μ€‘μš”ν•˜λ‹€ πŸ™‚
728x90
728x90