프로그래밍/iOS

[iOS] applicationWillResignActive(_:)가 호출되지 않을 때(푸시 알림)

turu 2020. 10. 11. 23:58

문제 상황:

UserNotification 프레임워크를 이용해서 로컬 푸시알림을 구현 중,

백그라운드에 들어갈 때 호출되는 메소드 applicationWillResignActive(_:)이 호출되지 않아, 푸시알림이 오지 않는 것 처럼 보이는 일이 발생함.

 

발생 원인:

iOS 13 이후 변경된 생명주기 이벤트 전달 방식 때문임.

백그라운드에 들어갔을 때 호출되는 메소드는

AppDelegate.swift의 applicationWillResignActive(_:)가 아닌,

SceneDelegate.swift의 sceneWillResignActive(_:)임.

 

 

해결 방법:

SceneDelegate의 sceneWillResignActive(_:)에서 처리해주면 됨

 

 

 

 

참고:

developer.apple.com/documentation/uikit/uiapplicationdelegate/1622950-applicationwillresignactive

 

Apple Developer Documentation

 

developer.apple.com

stackoverflow.com/questions/56508764/app-delegate-methods-arent-being-called-in-ios-13

 

App delegate methods aren't being called in iOS 13

I am using Xcode 11 and building an app for iOS 13. In a new project I created in Xcode some of the UIApplicationDelegate methods were missing so I added them back into the app delegate file. The new

stackoverflow.com

Msg-Notification.zip
0.06MB

반응형