iOS 개발/iOS

[WWDC19] Architecting Your App for Multiple Windows

꽁치대디 2023. 3. 7. 15:19

[WWDC19] Architecting Your App for Multiple Windows

https://developer.apple.com/videos/play/wwdc2019/258/

 

Architecting Your App for Multiple Windows - WWDC19 - Videos - Apple Developer

Dive into the details about what it means to support multitasking in iOS 13. Understand how previous best practices fit together with new...

developer.apple.com

제가 이해한 부분 위주로 정말 대충 정리했습니다 ㅡ.,ㅡ ;;

반박 시 님 말이 다 맞음

~ iOS 12

  • AppDelegate (iOS 12 and earlier)
    • Process LifeCycle
      • notify application of process level events
      • system notifies AppDelegate when process was launching or was about to terminate
    • UI LifeCycle
      • notify the state of UI
  • process : UI == 1 : 1
  • didFinishLaunchingWithOptions
    1. DB 연결, 데이터 구조 초기화 등 UI 가 아닌 일회성 global setup 수행
    2. UI setup

iOS 13 ~

  • 하나의 process 공유 but, may have mutiple UI or Scene sessions
  • AppDelegate 책임이 약간 변경 …
    • process event, lifecycle 담당하지만 UI lifecycle 관련 사항은 더 이상 책임지지 않음
    • SceneDelegate 가 할것임!

  • 새로운 scene session 이 생성되거나 삭제될 때 AppDelegate 에게 notify

  • 실제 UIScene 을 생성하기 전 configuartionForSession 호출
    • application 에 UIScene Configuration 을 요청하는 것
    • 어떤 SceneDelegate, 어떤 스토리보드, 어떤 Scene Subclass … (?)
    • info.plist 에서 configuartion 설정 가능
  • SceneDelegate 에서 UIWindow 인스턴스 생성 (willConnectToSession)
    • 사용자 상태 복원도 확인해야함!
    • window 인스턴스 만들어서 앱 화면 출력

  • 홈 화면으로 나가면 willResignActivedidEnterBackground 순차적으로 호출
    • 자원 회수를 위해 Scene 이 background 에 들어간 후 어느 시점에 메모리에서 해제 가능
    • 이는 SceneDelegate 가 메모리에서 해제되고 SceneDelegate 가 보유한 모든 window, view 계층이 해제됨을 의미
    • 해당 Scene 과 연관된 큰 리소스를 할당 해제할 수 있음
    • 하지만 Scene 이 복원될 경우를 고려하여 실제로 해당 데이터나 상태를 삭제해서는 안됨

  • 사용자가 app switcher 에서 정말 앱을 꺼버렸다면 …
    • didDiscardSceneSession 호출
    • 앱 프로세스가 실행되지 않는 동안 Switcher 에서 하나 이상의 UIScene 제거 가능
    • 프로세스가 실행되고 있지 않은 경우 discarded session 을 추적하고 앱의 다음 실행 직후에 호출 (?)

State Restoration

  • iOS 13 에서는 상태 복원 예전만큼 어렵지 않음 ~~…
  • scene-based state restoration 구현 하는것이 중요
    • 만약 어떤 scene 이 background 에 머물다가 disconnected 되고나서 나중에 그 scene 에 접근하려고 할 때, 이전 상태가 저장되어 있지 않다면 좋지 않은 UX
  • scene-based state restoration API

  • view hierachy 를 인코딩하지 않고 window 를 재생성할 수 있는 state 를 인코딩하는 방식으로 작동
  • SceneDelegate 의 메소드

  • UserActivity 찾아서 리턴
  • willConnectTo 에서 복원

Keeping Scenes in Sync

  • multiple windows 에서의 문제 …
  • 같은 Scene 이 2개 있는 경우 하나만 업데이트 될 때

  • ViewController 가 명시적으로 하나의 View 만 업데이트해서 발생하는 문제

  • Model Controller 가 관련된 subscribers 혹은 ViewController 에게 업데이트 하도록 알림
  • delegate, notifications, Combine … 사용 가능

 

'iOS 개발 > iOS' 카테고리의 다른 글

[iOS] 이미지 캐시 모듈 구현하기 (feat. Kingfisher)  (0) 2022.12.28
[iOS] 메모리 구조  (0) 2022.07.12
[iOS] Delegate Pattern  (0) 2022.07.06
[iOS] UINavigationController  (0) 2022.06.30
[iOS] 앱 생명주기 (App LifeCycle)  (0) 2022.06.24