@@ -759,8 +759,7 @@ - (void)flushCompletionHandlerQueue
759759{
760760 if (pendingCompletionHandlers != nil ) {
761761 for (NSString *key in [pendingCompletionHandlers allKeys ]) {
762- // Do not remove from the pending handlers for now, as it's removed after the enumeration finished
763- [self performCompletionHandlerWithKey: key andResult: UIBackgroundFetchResultFailed removeAfterExecution: NO ];
762+ [self performCompletionHandlerWithKey: key andResult: UIBackgroundFetchResultFailed];
764763 }
765764 }
766765 RELEASE_TO_NIL (pendingCompletionHandlers);
@@ -772,19 +771,17 @@ - (void)fireCompletionHandler:(NSTimer *)timer
772771 NSString *key = (NSString *)timer.userInfo ;
773772 if ([pendingCompletionHandlers objectForKey: key]) {
774773 // Send an event notifying the developer that the background-fetch failed
775- [self performCompletionHandlerWithKey: key andResult: UIBackgroundFetchResultFailed removeAfterExecution: YES ];
774+ [self performCompletionHandlerWithKey: key andResult: UIBackgroundFetchResultFailed];
776775 }
777776}
778777
779778// Gets called when user ends finishes with backgrounding stuff. By default this would always be called with UIBackgroundFetchResultNoData.
780- - (void )performCompletionHandlerWithKey : (NSString *)key andResult : (UIBackgroundFetchResult)result removeAfterExecution : ( BOOL ) removeAfterExecution
779+ - (void )performCompletionHandlerWithKey : (NSString *)key andResult : (UIBackgroundFetchResult)result
781780{
782- if ([pendingCompletionHandlers objectForKey: key]) {
783- void (^completionHandler)(UIBackgroundFetchResult) = [pendingCompletionHandlers objectForKey: key];
781+ void (^completionHandler)(UIBackgroundFetchResult) = [pendingCompletionHandlers objectForKey: key];
782+ if (completionHandler != nil ) {
783+ [pendingCompletionHandlers removeObjectForKey: key];
784784 completionHandler (result);
785- if (removeAfterExecution) {
786- [pendingCompletionHandlers removeObjectForKey: key];
787- }
788785 } else {
789786 DebugLog (@" [ERROR] The specified completion handler with ID = %@ has already expired or been removed from the system" , key);
790787 }
0 commit comments