I've been using AFNetworking
for sync information and found that it sends more than one request to the server when I apply multithreading
but I only execute one request statement.
This problem can be traced using a sniffer application, because Xcode debugger
can't make a trace of the request.
Also , I noticed this happen when the internet connection slows down.
Here is some code that I execute
Start sync
- (void)SyncFull { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FinishSyncFull:) name:@"FinishSyncFull" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(RemoveNotificacions:) name:@"RemoveNotificacions" object:nil]; [[PivotService getInstance] sync]; }
Notification to continue synchronizing
-(void)FinishSyncFull:(NSNotification*) Notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"FinishSyncFull" object:nil]; if ([SyncManager getInstance] mustSync]) { [[FMDBHelper getInstance] RemoveDataFromTable:@"SyncInfo"]; [[FMDBHelper getInstance] RemoveDataFromTable:@"SyncDetails"]; [self startSyncFull]; } }
Description of startSyncFull
function:
- (void)startSyncFull
{
[[ServiceEntity1 getInstance] sync];
[[ServiceEntity2 getInstance] sync];
[[ServiceEntity3 getInstance] sync];
(...)
}