我一直在使用AFNetworking
獲取同步信息,並發現當我申請multithreading
時,它向服務器發送多個請求,但我只執行一個請求語句。iOS:AFNetworking中意外的重複請求
使用嗅探器應用程序可以追蹤此問題,因爲Xcode debugger
無法追蹤請求。
另外,我注意到這種情況發生在互聯網連接速度變慢時。
下面是一些代碼,我執行
開始同步
- (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]; }
通知繼續同步
-(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]; } }
說明startSyncFull
功能:
- (void)startSyncFull
{
[[ServiceEntity1 getInstance] sync];
[[ServiceEntity2 getInstance] sync];
[[ServiceEntity3 getInstance] sync];
(...)
}
您是否向所有執行請求的地方添加了斷點,以確認您確實沒有執行多個地方? – KlausCPH
我證實他們沒有執行多個調試代碼。 – JosL92