ios - 如何从 [NSNotificationQueue defaultQueue] 中取出所有通知?

标签 ios nsnotificationcenter nsnotifications

我正在尝试测试是否发送了异步 NSNotifcation,并且我想在检查是否收到通知之前确保所有通知都已出队。

看来我不能使用NSNotificationQueue唯一的dequeue方法,

- (void)dequeueNotificationsMatching:(NSNotification *)notification coalesceMask:(NSUInteger)coalesceMask

因为我的测试不知道这个通知,所以它不能匹配它。

最佳答案

通知是通过 NSPostingStyleNSPostWhenIdle 设置的,因此解决方案是在验证模拟之前包含这一行。

  [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.1]];

关于ios - 如何从 [NSNotificationQueue defaultQueue] 中取出所有通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15644118/

相关文章:

ios - 如何在进度更改时更改 UIProgressView 颜色

ios - 如何将设备的系统铃声设置为本地通知音?

ios - 如何列出对象正在观察的所有通知?

ios - NSNotificationCenter postNotificationName 在 swift 和 object-c 中崩溃,为什么?

objective-c - 有没有办法监控 Mac 何时即将进入休眠状态?

ios - 有效的配置文件均不包含设备

iOS 8 : How to use segues

cocoa - 强制调用委托(delegate)方法

ios - 如何在iOS中获取系统通知

ios - anyobject 在 SWIFT 中没有成员命名的 objectforkey