1 removeObserver不要忘记调用了,否则Observer对象被释放后是会Crash的.
2 postNotification是同步的,也就是A 在postNotification 之后需要等到B 接收到Notification
3 接收消息的回调函数是和postNotification在同一个线程的,和addObserver以及removeObserver在哪个线程无关
APPLE官方文档相关内容以及链接:
A notification center delivers notifications to observers synchronously. In other words, when posting a notification, control does not return to the poster until all observers have received and processed the notification. To send notifications asynchronously use a notification queue, which is described in Notification Queues.
In a multithreaded application, notifications are always delivered in the thread in which the notification was posted, which may not be the same thread in which an observer registered itself.
来源于:
以上.
本文总结了NSNotification在使用过程中的几个关键点,包括removeObserver的重要性、postNotification的同步特性以及通知传递的线程行为。对于多线程应用,NSNotification总是在发布通知的线程中传递,与观察者的注册线程无关。

702

被折叠的 条评论
为什么被折叠?



