[iOS] applicationWillResignActive 메서드가 실행되지 않는다면!?

Ujeon 🍵
Jul 27, 2021

iOS에서 로컬 알림을 구현하기 위해 UIMutableNotificationContent 클래스를 사용하여 알림 컨텐츠 객체를 생성하고, 알림 컨텐츠와 기타 설정을 한 다음UNNotificationRequest 클래스를 초기화해서 알림 요청 객체를 생성했습니다.

그리고 만들어진 알림 요청 객체를 UNUserNotificationCenter.current() 를 사용하여 인스턴스를 받아온 뒤 add 메서드를 사용하여 알림을 추가하는 로직을 구현하였습니다.

만들어진 로직을 AppDelgate 클래스에 applicationWillResignActive 메서드를 만들어 그 안에 정의하였습니다.

이제 앱이 비활성화 될 때 알림이 오기만 하면 되는데… 오질 않더라구요 😅 :

앱이 비활성화 될 때 실행된다 했는데…

원인은 앱에서 scenes을 사용하고 있다면 UIKit가 applicationWillResignActive 를 호출하지 않고 sceneWillResignActive 를 호출하기 때문이라고 합니다 :

sceneWillResignActive 메서드는 SceneDelegate 클래스에 정의되어 있습니다. 위 로컬 알림 발송 로직을 sceneWillResignActive 로 옮겨주면 알림이 잘 오는 것을 확인할 수 있습니다 🙌 :

SceneDelegate의 sceneWillResignActive 메서드
정상적으로 알림이 옵니다! 👍

참고 자료

applicationWillResignActive(_:)

--

--

Ujeon 🍵

Hi there, this is Ujeon. I want to be a developer who passes on value through development :)