Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSNotificationCenter流-在iAction中等待postNotification_Ios_Objective C_Nsnotificationcenter - Fatal编程技术网

Ios NSNotificationCenter流-在iAction中等待postNotification

Ios NSNotificationCenter流-在iAction中等待postNotification,ios,objective-c,nsnotificationcenter,Ios,Objective C,Nsnotificationcenter,在我的iOS应用程序中,我想在用户打开新的ViewController时执行后台任务。在这个特定的实例中,我在服务器上处理一些图像,并返回从这些图像创建的GIF的URL 在同一个ViewController中,我有一个按钮,允许用户下载GIF。我想设计这样一种情况:当GIF仍在服务器上创建时,用户尝试下载GIF 我目前在我的应用程序中设置它的方式是,我在ViewWillDisplay中添加一个侦听器: [[NSNotificationCenter defaultCenter] addObserv

在我的iOS应用程序中,我想在用户打开新的ViewController时执行后台任务。在这个特定的实例中,我在服务器上处理一些图像,并返回从这些图像创建的GIF的URL

在同一个ViewController中,我有一个按钮,允许用户下载GIF。我想设计这样一种情况:当GIF仍在服务器上创建时,用户尝试下载GIF

我目前在我的应用程序中设置它的方式是,我在ViewWillDisplay中添加一个侦听器:

[[NSNotificationCenter defaultCenter] addObserver:self selector:nil name:@"generatedGIF" object:nil];
然后,我在后台使用该方法处理GIF

[self generateSpinGIF];
然后在generateSpinGIf方法中,我在服务器上创建GIF后发布通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"generatedGIF" object:self];
另外,我有一个iAction来检测用户何时点击按钮下载GIF。此时,如果GIF已经存在,我想下载它,或者等待后台处理完成


实现这一点的方法是什么?

不要使用通知,而是在视图控制器的成员变量中创建gcd队列。使用dispatch_async创建GIF。当用户点击按钮时,使用同一队列上的dispatch_sync检索GIF。如果GIF已经存在,调度同步将立即执行。如果创建过程尚未完成,它将阻塞,直到创建完成