Преглед на файлове

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 години
родител
ревизия
61bcf5354a
променени са 2 файла, в които са добавени 15 реда и са изтрити 9 реда
  1. 2 5
      Classes/Network/FLEXNetworkHistoryTableViewController.m
  2. 13 4
      Classes/Network/FLEXNetworkRecorder.m

+ 2 - 5
Classes/Network/FLEXNetworkHistoryTableViewController.m

@@ -68,11 +68,8 @@
 
 
 - (void)handleNewTransactionRecordedNotification:(NSNotification *)notification
 - (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
 #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.orderedTransactions addObject:transaction];
     [self.networkTransactionsForRequestIdentifiers setObject:transaction forKey:requestId];
     [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
 - (void)recordResponseReceivedWithRequestId:(NSString *)requestId response:(NSURLResponse *)response
@@ -132,10 +131,20 @@ NSString *const kFLEXNetworkRecorderUserInfoTransactionKey = @"transaction";
     [self postUpdateNotificationForTransaction: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
 - (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
 @end