@@ -46,21 +46,19 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
4646 _fileQueue.maxConcurrentOperationCount = 4 ;
4747 }
4848
49- __weak __block NSBlockOperation *weakOp ;
50- __block NSBlockOperation *op = [ NSBlockOperation blockOperationWithBlock: ^{
51- // [macOS
52- NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
49+ NSBlockOperation *op = [ NSBlockOperation new ] ;
50+ __weak NSBlockOperation *weakOp = op;
51+ [op addExecutionBlock: ^{
52+ NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
5353 if (strongOp == nil || [strongOp isCancelled ]) {
5454 return ;
5555 }
56- // macOS]
57-
5856 // Get content length
5957 NSError *error = nil ;
6058 NSFileManager *fileManager = [NSFileManager new ];
6159 NSDictionary <NSString *, id > *fileAttributes = [fileManager attributesOfItemAtPath: request.URL.path error: &error];
6260 if (!fileAttributes) {
63- [delegate URLRequest: strongOp didCompleteWithError: error]; // [macOS]
61+ [delegate URLRequest: strongOp didCompleteWithError: error];
6462 return ;
6563 }
6664
@@ -77,17 +75,16 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
7775 expectedContentLength: [fileAttributes[NSFileSize ] ?: @-1 integerValue ]
7876 textEncodingName: nil ];
7977
80- [delegate URLRequest: strongOp didReceiveResponse: response]; // [macOS]
78+ [delegate URLRequest: strongOp didReceiveResponse: response];
8179
8280 // Load data
8381 NSData *data = [NSData dataWithContentsOfURL: request.URL options: NSDataReadingMappedIfSafe error: &error];
8482 if (data) {
85- [delegate URLRequest: strongOp didReceiveData: data]; // [macOS]
83+ [delegate URLRequest: strongOp didReceiveData: data];
8684 }
87- [delegate URLRequest: strongOp didCompleteWithError: error]; // [macOS]
85+ [delegate URLRequest: strongOp didCompleteWithError: error];
8886 }];
8987
90- weakOp = op;
9188 [_fileQueue addOperation: op];
9289 return op;
9390}
0 commit comments