有没有办法像线程一样调用 NSNotificationQueue ?
是否可以像这样运行通知,
-(void) testMethod
{
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"TEST123" object:self userInfo:parms]postingStyle:NSPostNow coalesceMask:NSNotificationNoCoalescing forModes:nil];
NSLog(@"test123");
//.....
以便“-(void)testMethod”继续执行 NSLog,...,而无需完成通知调用的方法。 有没有办法在没有线程的情况下解决这个问题?
Is it possible to run the notifications like
-(void) testMethod
{
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"TEST123" object:self userInfo:parms]postingStyle:NSPostNow coalesceMask:NSNotificationNoCoalescing forModes:nil];
NSLog(@"test123");
//.....
so that the "-(void)testMethod" go on an execute the NSLog,..., without that the methods, which are called by the notifications did finish.
Is there anyway to solve it, without threads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您想异步调用方法。
答案是否定的:您不能在同一线程中异步调用方法。
检查文档:
I think you want to invoke methods asynchronously.
The answer is NO: you can't invoke methods asynchronously in the same thread.
Check the docs:
NSNotificationQueue 不用于异步目的。
参考:
NSNotificationQueue 对象(或简称通知队列)充当通知中心(NSNotificationCenter 的实例)的缓冲区。通知中心在发布时分发通知,而放入队列中的通知可以延迟,直到运行循环的当前传递结束或直到运行循环空闲。还可以合并重复的通知,以便在发布多条通知的同时仅发送一条通知
NSNotificationQueue is not used for asynchronous purpose.
Reference:
NSNotificationQueue objects (or simply notification queues) act as buffers for notification centers (instances of NSNotificationCenter). Whereas a notification center distributes notifications when posted, notifications placed into the queue can be delayed until the end of the current pass through the run loop or until the run loop is idle. Duplicate notifications can also be coalesced so that only one notification is sent although multiple notifications are posted