May 06, 2021, TIL (Today I Learned) - Scene Delegate & App Delegate

Inwoo Hwang·2021년 8월 26일
0
post-thumbnail

layout: post
title: "May 06, 2021, TIL (Today I Learned) - Scene Delegate & App Delegate"
summary: "iOS 커리어 스타터 캠프 2기"
author: inwoodev
date: '2021-05-06 22:35:23 +0530'
category: ['Swift_iOS', 'Protoocol', 'TIL']
thumbnail: /assets/img/posts/light-bulbs.jpg
keywords: ios, swift, protocol, app delegate, scene delegate
permalink: /blog/TIL(Today I Learned)/39
usemathjax: true


수업 내용


Managing Your App's Life Cycle

Respond to Scene-Based Life-Cycle Events

Respond to App-Based Life-Cycle Events

iOS 13에서 Scene Delegate로 이관된 App Delegate의 역할은 무엇무엇이 있을까?

  • UI의 상태를 알 수 있는 AppLifeCycle에 대한 부분

예)

application: willEnterForeGroundscene: willEnterForeground

application:willEnterForegroundscene:willEnterForeground
application:didEnterBackgroundscene:didEnterBackground application:willResignActivescene:willResignActive

application:didBecomeActivescene:didBecomeActive

App Delegate와 Scene Delegate의 각각의 역할은 무엇일까?

AppDelegate

  • AppDelegate은 iOS 버전에 무관하게 application의 entry point 역할
  • application level의 life-cycle을 관리
  • 새로운 Session이 만들어지는 것을 알리거나, 기존의 Session이 discarded 된 것을 알린다
  • UISceneSession = An object that contains information about one of your app's scenes.

SceneDelegate

  • 화면에 무엇(scene/window)을 보여줄지 관리하는 역할

Scene의 개념이 생긴 이유는 무엇이고, 언제 어디서 활용해볼 수 있을까?

  • ios 12까지는 한개의 앱이 하나의 window만 가질 수 있었음.
  • ios 13부터는 window 개념이 scene으로 대체 됨. 앱은 하나 이상의 scene을 가질 수 있게 됨.

Life Cycle에서 Unattached, Suspended, Not Running의 메모리와 프로세스의 관점에서의 차이는 무엇일까?

  • Unattached - scene시스템으로 부터 connection notification을 받기 전까지는 이 상태를 유지한다. 따라서 메모리를 점유하고 있고, 실행 중인 상태라고 할 수 있다.
  • Not Running - 앱이 아직 실행되지 않거나 완전히 종료된 상태다. 메모리에 올라가지 않았다.
    • 아예 App실행되지 않았거나, 실행이 되었었지만 시스템에 의해서 종료된 상태이다. 따라서 메모리에도 없고, 프로세스의 관점에서도 아무 것도 실행되지 않는다.
  • Suspended - 앱이 background 상태에 있지만 코드를 실행시키고 있지 않은 상태. 앱이 background 상태로 전환된 후 더이상 작업을 수행하지 않으면 시스템에서 앱을 Suspend 상태로 바꾼다. 앱은 여전히 메모리에 존재하며 Suspend 상태가 될 당시의 상태를 저장하고 있지만, CPU나 배터리를 소모하지 않는다. Suspend 상태의 앱은 foreground 상태의 앱을 위해 메모리 부족 등의 이유로 시스템에 의해 언제든지 종료된다. 이후 앱을 실행하면 이전 상태의 화면은 나오지 않고 앱이 재시작 된다.
  • Background - App이나 scene백그라운드에 있고 아무것도 실행되지 않는 즉, 프로세스 대기 상태이다. 따라서 메모리는 점유하지만 대기중인 상태라고 할 수 있다.

App Life Cycle 모식도의 점선과 실선의 차이는 무엇일까?

https://www.howtogeek.com/441373/how-to-use-multiple-windows-of-an-app-on-your-ipad/

https://zeddios.tistory.com/811

https://velog.io/@dev-lena/iOS-AppDelegate%EC%99%80-SceneDelegate

https://usinuniverse.bitbucket.io/blog/scenedelegatepart1.html

http://monibu1548.github.io/2018/08/28/appdelegate/

학습내용


궁금증 1: waitUntilAllOperations

func serveClient(_ data: HeadBankTask) {
        let semaphore = DispatchSemaphore(value: 1)
        bankWindow.maxConcurrentOperationCount = 1
        let headBankTask = HeadBankTask()
        headBankTask.waitingNumber = data.waitingNumber
        headBankTask.creditRate = data.creditRate
        headBankTask.workType = data.workType
        semaphore.wait()
        bankWindow.addOperation(headBankTask)
        semaphore.signal()
        // 밑에 중 무엇을 써야 할까
        headBankTask.waitUntilFinished()
        bankWindow.waitUntilAllOperationsAreFinished()
    }

profile
james, the enthusiastic developer

0개의 댓글