Ios 操作失败时收到通知

Ios 操作失败时收到通知,ios,objective-c,swift,Ios,Objective C,Swift,我正在使用后台操作发出URL请求。 如果操作返回错误,如何通知我,然后将相同的操作类型重新添加到队列以重试?您可以使用NSNotification进行此操作。创建通知并在请求失败时发布。在控制器中侦听通知 下面的例子 添加用于通知的侦听器: NSString *notificationName = @"RequestFailed"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(failed

我正在使用后台操作发出URL请求。
如果操作返回错误,如何通知我,然后将相同的操作类型重新添加到队列以重试?

您可以使用NSNotification进行此操作。创建通知并在请求失败时发布。在控制器中侦听通知

下面的例子

添加用于通知的侦听器:

NSString *notificationName = @"RequestFailed";

[[NSNotificationCenter defaultCenter] 
addObserver:self
selector:@selector(failedRequestNotification:) 
name:notificationName 
object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:nil]
张贴通知:

NSString *notificationName = @"RequestFailed";

[[NSNotificationCenter defaultCenter] 
addObserver:self
selector:@selector(failedRequestNotification:) 
name:notificationName 
object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:nil]

谢谢你的建议,我的问题更多的是在操作失败时得到通知,而不是返回时没有错误。