반응형
SwiftUI로 Background나 Foreground 진입시 처리하는 방법은 Combine을 사용해서 Notification을 Publisher 하는 것보다는 다음과 같이 scenePhase 환경변수를 사용하는게 더 편리합니다.(iOS 14 이상)
@Environment(\.scenePhase) private var scenePhase
...
var body: some View {
Text("Hello!!")
.onChange(of: scenePhase) { newPhase in
switch newPhase {
case .active:
print(">>> active")
case .inactive:
print(">>> inactive")
case .background:
print(">>> background")
default:
break
}
}
}
반응형
'Dev Study > iOS' 카테고리의 다른 글
| Mac OS 업데이트 이후 Xcode 실행 (0) | 2024.12.11 |
|---|---|
| XCode - Unable to process request - PLA Update available (0) | 2024.11.17 |
| 다크모드 'traitCollectionDidChange’ deprecated in iOS 17.0 (0) | 2024.03.22 |
| 휴대전화번호 포멧(000-0000-0000)으로 만들기 (0) | 2024.01.16 |
| Background, Foreground 진입시 처리 (0) | 2024.01.04 |
| SegmentView (0) | 2023.12.30 |
| UITextField hyphen(-) 연속 입력시 en dash(–)로 변경되는것 막기 (0) | 2023.12.14 |
| Keyboard Height 계산해서 Publisher 하기 (0) | 2023.12.13 |


