2017-01-15 6 views
0

ViewController.m[NSNotificationCenter defaultCenter]에 옵서버로 등록되어 작동합니다. 그러나 ViewControllerviewDidLoad 방법으로 X를합니다.관찰자가 NSNotificationCenter에서 알림을 받았는지 여부를 알 수있는 방법이 있습니까?

나는 통지를하지 않았다 ViewController 경우 X가 발생하고 싶습니다.

아키텍처가 실제로 깨질 수도 있지만 내 데이터가있는 경우 내 질문은 defaultCenter은 관찰자에게 알림이 있는지 알려줍니다.

+1

통지 디자인 방송이 아닌 직접 위임을 조사하고 싶을 것 같은 디자인의 소리가 들리면 - "화재와 잊음"알림을 고려해보십시오. – luk2302

+0

맞습니다. 질문을 편집했습니다. – wp42

답변

0

우리가 관찰자에게 보낸 notification을 수신했는지 알 수있는 콜백 메소드가 없습니다.

Notification Center 방법에 따라 우리는 엑스 코드에서 얻을 수 있습니다 :

/**************** Notification Center ****************/ 
open class NotificationCenter : NSObject { 


    open class var `default`: NotificationCenter { get } 


    open func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?) 


    open func post(_ notification: Notification) 

    open func post(name aName: NSNotification.Name, object anObject: Any?) 

    open func post(name aName: NSNotification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) 


    open func removeObserver(_ observer: Any) 

    open func removeObserver(_ observer: Any, name aName: NSNotification.Name?, object anObject: Any?) 


    @available(iOS 4.0, *) 
    open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Swift.Void) -> NSObjectProtocol 
} 

을 그리고 우리는, 우리는 그 기능이 배워야한다 NotificationCenterapple docs을 참조 할 수 있습니다 :

객체 알림에 등록 addObserver (_ : selector : name : object :) 또는 addObserver (forName : object : queue : using :) 메소드를 사용하여 알림 (NSNotification 객체)을 수신 할 센터.

그리고 docs에서 귀하의 요구 사항에 대한 언급을 찾을 수 없습니다.

+0

정확함, 고맙습니다. – wp42