Ver código fonte

Post recorder notifications on the main thread so observers don’t need to worry about which thread the notification is posted on.

Ryan Olson 11 anos atrás
pai
commit
61bcf5354a

+ 2 - 5
Classes/Network/FLEXNetworkHistoryTableViewController.m

@@ -68,11 +68,8 @@
 
 - (void)handleNewTransactionRecordedNotification:(NSNotification *)notification
 {
-    // Note that these notifications may be posted from a background thread.
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [self updateTransactions];
-        [self.tableView reloadData];
-    });
+    [self updateTransactions];
+    [self.tableView reloadData];
 }
 
 #pragma mark - Table view data source

+ 13 - 4
Classes/Network/FLEXNetworkRecorder.m

@@ -73,8 +73,7 @@ NSString *const kFLEXNetworkRecorderUserInfoTransactionKey = @"transaction";
     [self.orderedTransactions addObject:transaction];
     [self.networkTransactionsForRequestIdentifiers setObject:transaction forKey:requestId];
 
-    NSDictionary *userInfo = @{ kFLEXNetworkRecorderUserInfoTransactionKey : transaction };
-    [[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkRecorderNewTransactionNotification object:self userInfo:userInfo];
+    [self postNewTransactionNotificationWithTransaction:transaction];
 }
 
 - (void)recordResponseReceivedWithRequestId:(NSString *)requestId response:(NSURLResponse *)response
@@ -132,10 +131,20 @@ NSString *const kFLEXNetworkRecorderUserInfoTransactionKey = @"transaction";
     [self postUpdateNotificationForTransaction:transaction];
 }
 
+- (void)postNewTransactionNotificationWithTransaction:(FLEXNetworkTransaction *)transaction
+{
+    dispatch_async(dispatch_get_main_queue(), ^{
+        NSDictionary *userInfo = @{ kFLEXNetworkRecorderUserInfoTransactionKey : transaction };
+        [[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkRecorderNewTransactionNotification object:self userInfo:userInfo];
+    });
+}
+
 - (void)postUpdateNotificationForTransaction:(FLEXNetworkTransaction *)transaction
 {
-    NSDictionary *userInfo = @{ kFLEXNetworkRecorderUserInfoTransactionKey : transaction };
-    [[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkRecorderTransactionUpdatedNotification object:self userInfo:userInfo];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        NSDictionary *userInfo = @{ kFLEXNetworkRecorderUserInfoTransactionKey : transaction };
+        [[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkRecorderTransactionUpdatedNotification object:self userInfo:userInfo];
+    });
 }
 
 @end