이상한 문제가 있습니다. 나는 다음과 같이 내 알림을 등록 및 등록 취소합니다.알림을위한 removeObserver Swift3
func doRegisterNotificationListener() {
NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: "RateAlertRated"), object: nil, queue: nil, using: rateDidRate)
}
func doUnregisterNotificationListener() {
NotificationCenter.default.removeObserver(self, name: Notification.Name(rawValue: "RateAlertRated"), object: nil)
}
func rateDidRate(notification: Notification) {
let rating = notification.userInfo?["score"] as? Int
let message = notification.userInfo?["message"] as? String
let response = Response(rating: rating, message: message)
output.presentRated(response)
}
이보기 컨트롤러는 UITabBarController에 있습니다. doRegisterNotificationListener
이 viewDidAppear
에 있고 doUnregisterNotificationListener
이 viewDidDisappear
에 호출되었습니다. 탭간에 전환 할 때 register 및 unregister 메서드가 올바르게 호출되고 있습니다 (print 문을 사용하여 테스트했습니다). 그러나 알림을 실행하면 doUnregisterNotificationListener
이 마지막으로 호출 되었더라도 계속 수신됩니다. 내가 여기서 잘못하고있는 아이디어가 있습니까?
빠른 참고 : 또한 시도
는 :
NotificationCenter.default.removeObserver(self)
이 또한 작동하지 않습니다. 당신이 addObserver(forName:object:queue:using:)
로 작업하는 경우
당신은 또한 관찰자로의 ViewController를 제거 할 수있는 것은 deinit 방법에 NotificationCenter.default.removeObserver (자신을)이 시도 – Pankaj
@Prince 그와 차이 – KexAri