[Swift] UISceneDelegate
2023. 11. 9. 13:01
UISceneDelegate
Scene 내에서 발생하는 수명 주기(Life Cycle) 이벤트에 응답하는 데 사용하는 핵심 방법
Connecting and disconnecting the scene
scene(_:willConnectTo:options:) : Delegate에 앱의 Scene을 추가하는 것을 알림
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.backgroundColor = .systemBackground
window?.rootViewController = UIViewController()
window?.tintColor = .label
window?.makeKeyAndVisible()
}
sceneDidDisconnect(_:) : Delegate에 UIKit에서 앱의 Scene을 제거했다고 알림
UIScene.ConnectionOptions : UIKit에서 Scene을 생성한 이유에 대한 정보를 포함한 데이터 객체 (Class)
Transitioning to the foreground (foreground로 전환 중)
scenewillEnterForeground(_:)
Scene이 foreground에서 실행되기 시작하고 사용자에게 표시될 것을 Delegate에 알림
sceneDidBecomeActive(_:)
Scene이 활성화되어 이제 사용자 event에 응답하고 있음을 Delegate에 알림 (scenewillEnterForeground 이후)
Transitioning to the background (background로 전환 중)
sceneWillResignActive(_:)
Scene이 활성 상태를 종료하고 사용자 event에 대한 응답을 중지한다고 Delegate에 알림
sceneDidEnterBackground(_:)
Scene이 background에서 실행 중이며, 더 이상 화면에 표시되지 않음을 Delegate에 알림
(scenewillResignActive 이후 실행)
Opening URLs
scene(_:openURLContexts:)
Delegate에 하나 이상의 URL을 열도록 요청
※ 다른 앱에서 데이터 가져오기
1. willConnectTo 에서 delegate 선언
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
static weak var shared: SceneDelegate? // 선언
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let sceneDelegate = scene.delegate as? SceneDelegate {
SceneDelegate.shared = sceneDelegate
}
}
}
2. openURLContext()에서 가져오기
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
// 결과값
if let url = URLContexts.first?.url{
}
}
728x90
'iOS > Swift' 카테고리의 다른 글
[Swift] RelativeDateTimeFormatter(상대시간) (0) | 2023.11.20 |
---|---|
[Swift] 공식문서 파헤치기 (Array, Set, Dictionary) (0) | 2023.11.11 |
[Swift] frame vs bounds (1) | 2023.10.28 |
[Swift] BackgroundTasks (0) | 2023.09.03 |
[Swift] Dynamic Library vs Static Library (0) | 2023.08.21 |