2022. 11. 9. 17:42ㆍiOS/iOS
앱은 background, foreground에 있는가에 따라서 시스템 알림에 응답하고 다른 중요한 시스템 관련된 이벤트를 처리하게 됩니다.
appdelegate에서 foreground ↔︎ background 전환에 대해 공부하던 중, 아래와 세개와 같은 함수를 발견해서 사용해보았지만 함수 호출이 되지 않았습니다. 이에 관련하여 stackoverflow에서 프로젝트의 info.plist에서 아래와 같은 property값을 NO로 설정하는것이 appdelegate에서 해당 함수들을 호출하는 방법이라고 했지만 해결되지 않았습니다.
참고 글)
applicationDidEnterBackground and applicationWillEnterForeground method are not called when pressed home button in iOS simulator
I need a long running task to be done in background as well as in foreground. This updates the core data. So to maintain UI responsive I created an another thread where I use different
stackoverflow.com
func applicationWillEnterForeground(_ application: UIApplication) {
DLog.d("🍞실행된 앱이 background에서 foreground로 이동될 때 실행되는 메서드 아직 foreground에서 실행x")
}
func applicationDidBecomeActive(_ application: UIApplication) {
DLog.d("🍞실행된 앱이 foreground에 표시될때 호출되는 메서드")
}
func applicationDidEnterBackground(_ application: UIApplication) {
DLog.d("🍞실행된 앱이 background에 진입했을때 호출되는 메서드")
}
그런데, scenedelegate에서 아래의 함수들을 구현해서 사용했을때 함수 호출이 되는것을 확인했고, 왜 appdelegate에선 작동이 안되는 함수가 scenedelegate에서는 작동이 되는지에 대해 고민하던중 아래의 글을 발견했습니다.
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
DLog.d("🥕실행된 앱이 foreground에 표시될때 호출되는 메서드")
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
DLog.d("🥕실행된 앱이 background에 진입했을때 호출되는 메서드")
}
참고 글) iOS Application Life Cycle
글의 내용인 즉슨
앱의 상태가 바뀔 때 UIKit은 적절한 delegate object의 method를 호출하여 우리에게 알려주는데,
- iOS 13 이상은 UISceneDelegate 개체를 사용하여 scene-based app에서 발생하는 life-cycle event에 응답하면 된다.
- iOS 12 이하는 life-cycle event에 응답하기 위해서 UIApplicationDelegate 개체를 사용하면 된다.
- iOS13 이상은 Appdelegate의 역할 중 UI의 상태를 알 수 있는 UILifeCycle에 대한 부분을 SceneDelegate가 대체한다
라는 내용이었습니다.
실제로, smartstore프로젝트의 Deployment Info가 iOS13버전 이상을 타겟으로 하기 때문에 UILifeCycle에 대한 부분을 appdelegate가 아닌 scenedeleate가 대체했었고, 그래서 appdelegate에서 호출되지 않았었음을 알게되었습니다.
결론)
1. WWDC열심히 보자.
2. 뭐가 어떻게 변화되는지를 알아야 몸이 덜 고생한다.
3. 부장님께 confluence내용 따봉받아서 기분좋음(tmi)
'iOS > iOS' 카테고리의 다른 글
bannaviiOS) background ver - fcm push 클릭시 서버에서 보내준 url대로 이동하는 코드 순서도 흐름 (0) | 2022.11.11 |
---|---|
bannaviiOS) foreground ver - fcm push 클릭시 서버에서 보내준 url대로 이동하는 코드 순서도 흐름 (0) | 2022.11.11 |
bannaviiOS) bundleid를 바꿨는데 push가 안올때 체크사항(feat. enterprise배포) (0) | 2022.11.07 |
bannaviiOS) push 사용중, bundleid를 바꿨는데 build fail일때 (0) | 2022.11.04 |
bannaviiOS) webView에서 사진, 카메라 사용하기 (0) | 2022.11.01 |