푸시메세지를 클릭했을 때 처리하는 메서드는 didReceive이다
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
switch UIApplication.shared.applicationState {
case .background:
processPayload(userInfo, false)
case .active, .inactive:
processPayload(userInfo, true)
default:
break
}
completionHandler()
}
UIApplication.shared.applicationState에 접근하여
.background, .inactive , .active등에 따라 다르게 처리할 수 있다 🙃
단, 위 상태는 앱이 메모리에 있을 때를 컨트롤 하는 법이고,
아예 죽은 상태에서부터 올라왔을 때 다르게 처리하고 싶으면 전역변수로 컨트롤 해주어야 한다!