@@ -320,43 +320,44 @@ - (void)sendRequests:(BOOL)async
320320 dispatch_semaphore_signal (semaphore);
321321 return ;
322322 }
323-
324- // Retry on 500 and other network failures.
325- NSInteger httpStatusCode = completedOperation.HTTPStatusCode ;
326- if (httpStatusCode == 408
327- || (httpStatusCode >= 500 && httpStatusCode < 600 )
328- || err.code == NSURLErrorBadServerResponse
329- || err.code == NSURLErrorCannotConnectToHost
330- || err.code == NSURLErrorDNSLookupFailed
331- || err.code == NSURLErrorNotConnectedToInternet
332- || err.code == NSURLErrorTimedOut) {
333- NSLog (@" Leanplum: %@ " , err);
334- } else {
335- id errorResponse = completedOperation.responseJSON ;
336- NSString *errorMessage = [LPResponse getResponseError: [LPResponse getLastResponse: errorResponse]];
337- if (errorMessage) {
338- if ([errorMessage hasPrefix: @" App not found" ]) {
339- errorMessage = @" No app matching the provided app ID was found." ;
340- constants.isInPermanentFailureState = YES ;
341- } else if ([errorMessage hasPrefix: @" Invalid access key" ]) {
342- errorMessage = @" The access key you provided is not valid for this app." ;
343- constants.isInPermanentFailureState = YES ;
344- } else if ([errorMessage hasPrefix: @" Development mode requested but not permitted" ]) {
345- errorMessage = @" A call to [Leanplum setAppIdForDevelopmentMode] with your production key was made, which is not permitted." ;
346- constants.isInPermanentFailureState = YES ;
347- }
348- NSLog (@" Leanplum: %@ " , errorMessage);
349- } else {
323+
324+ @synchronized ([LPEventCallbackManager eventCallbackMap ]) {
325+ // Retry on 500 and other network failures.
326+ NSInteger httpStatusCode = completedOperation.HTTPStatusCode ;
327+ if (httpStatusCode == 408
328+ || (httpStatusCode >= 500 && httpStatusCode < 600 )
329+ || err.code == NSURLErrorBadServerResponse
330+ || err.code == NSURLErrorCannotConnectToHost
331+ || err.code == NSURLErrorDNSLookupFailed
332+ || err.code == NSURLErrorNotConnectedToInternet
333+ || err.code == NSURLErrorTimedOut) {
350334 NSLog (@" Leanplum: %@ " , err);
335+ } else {
336+ id errorResponse = completedOperation.responseJSON ;
337+ NSString *errorMessage = [LPResponse getResponseError: [LPResponse getLastResponse: errorResponse]];
338+ if (errorMessage) {
339+ if ([errorMessage hasPrefix: @" App not found" ]) {
340+ errorMessage = @" No app matching the provided app ID was found." ;
341+ constants.isInPermanentFailureState = YES ;
342+ } else if ([errorMessage hasPrefix: @" Invalid access key" ]) {
343+ errorMessage = @" The access key you provided is not valid for this app." ;
344+ constants.isInPermanentFailureState = YES ;
345+ } else if ([errorMessage hasPrefix: @" Development mode requested but not permitted" ]) {
346+ errorMessage = @" A call to [Leanplum setAppIdForDevelopmentMode] with your production key was made, which is not permitted." ;
347+ constants.isInPermanentFailureState = YES ;
348+ }
349+ NSLog (@" Leanplum: %@ " , errorMessage);
350+ } else {
351+ NSLog (@" Leanplum: %@ " , err);
352+ }
353+
354+ // Delete on permanant error state.
355+ [LPEventDataManager deleteEventsWithLimit: requestsToSend.count];
351356 }
352-
353- // Delete on permanant error state.
354- [LPEventDataManager deleteEventsWithLimit: requestsToSend.count ];
357+ // Invoke errors on all requests.
358+ [LPEventCallbackManager invokeErrorCallbacksWithError: err];
359+ [[LeanplumRequest sendNowQueue ] cancelAllOperations ];
355360 }
356-
357- // Invoke errors on all requests.
358- [LPEventCallbackManager invokeErrorCallbacksWithError: err];
359- [[LeanplumRequest sendNowQueue ] cancelAllOperations ];
360361 dispatch_semaphore_signal (semaphore);
361362 LP_END_TRY
362363 }];
0 commit comments