반응형
앱이 백그라운드에서 실행되고 있는지를 체크하여 다시 활성화 되었을 때만 실행하고 싶은 코드가 있어 이를 체크해주는 메서드를 찾아보았다.
다음 메서드들이 바로 AppDelegate에서 제공되는 앱의 실행 상태를 감지해주는 메서드들이다.
func applicationDidEnterBackground(_ application: UIApplication) {
print("applicationDidEnterBackground")
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
print("applicationWillEnterForeground")
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("applicationDidBecomeActive")
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
//KOSession.handleDidBecomeActive()
}
func applicationWillTerminate(_ application: UIApplication) {
print("applicationWillTerminate")
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
비활성 -> 활성
applicationWillEnterForeground(_:)
: Tells the delegate that the app is about to enter the foreground.
앱이 처음 켜질 때는 실행되지 않는다. 백그라운드에 있다가 다시 넘어오면서 활성화될 때 호출되는 메서드.
applicationDidBecomeActive(_:)
: Tells the delegate that the app has become active.
앱이 처음 켜질 때도, 다시 활성화될 때도 호출되는 메서드.
728x90
반응형
'Swift iOS 앱 개발 > Swift' 카테고리의 다른 글
[Swift iOS] 검색기능구현 - 문자열 탐색 NSString.CompareOptions (0) | 2021.06.22 |
---|---|
[Swift iOS] LaunchScreen duration 이미지 및 노출 시간 설정 (0) | 2021.06.17 |
[Swift iOS] UITableView scrollToRow 특정 인덱스로 이동 (0) | 2021.06.01 |
[Swift iOS] sort JSON Array : JSON 데이터 배열 정렬하기 (0) | 2021.05.31 |
[RxSwift] RxCocoa Binding (0) | 2021.05.25 |