File tree 2 files changed +11
-21
lines changed
packages/react-native/Libraries/Network 2 files changed +11
-21
lines changed Original file line number Diff line number Diff line change @@ -49,13 +49,8 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
49
49
_queue.maxConcurrentOperationCount = 2 ;
50
50
}
51
51
52
- __weak NSBlockOperation *weakOp;
53
- NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
54
- NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
55
- if (strongOp == nil || [strongOp isCancelled ]) {
56
- return ;
57
- }
58
-
52
+ __weak __block NSBlockOperation *weakOp;
53
+ __block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
59
54
// Get mime type
60
55
NSRange firstSemicolon = [request.URL.resourceSpecifier rangeOfString: @" ;" ];
61
56
NSString *mimeType =
@@ -67,15 +62,15 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
67
62
expectedContentLength: -1
68
63
textEncodingName: nil ];
69
64
70
- [delegate URLRequest: strongOp didReceiveResponse: response];
65
+ [delegate URLRequest: weakOp didReceiveResponse: response];
71
66
72
67
// Load data
73
68
NSError *error;
74
69
NSData *data = [NSData dataWithContentsOfURL: request.URL options: NSDataReadingMappedIfSafe error: &error];
75
70
if (data) {
76
- [delegate URLRequest: strongOp didReceiveData: data];
71
+ [delegate URLRequest: weakOp didReceiveData: data];
77
72
}
78
- [delegate URLRequest: strongOp didCompleteWithError: error];
73
+ [delegate URLRequest: weakOp didCompleteWithError: error];
79
74
}];
80
75
81
76
weakOp = op;
Original file line number Diff line number Diff line change @@ -53,19 +53,14 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
53
53
_fileQueue.maxConcurrentOperationCount = 4 ;
54
54
}
55
55
56
- __weak NSBlockOperation *weakOp;
57
- NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
58
- NSBlockOperation *strongOp = weakOp; // Strong reference to avoid deallocation during execution
59
- if (strongOp == nil || [strongOp isCancelled ]) {
60
- return ;
61
- }
62
-
56
+ __weak __block NSBlockOperation *weakOp;
57
+ __block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
63
58
// Get content length
64
59
NSError *error = nil ;
65
60
NSFileManager *fileManager = [NSFileManager new ];
66
61
NSDictionary <NSString *, id > *fileAttributes = [fileManager attributesOfItemAtPath: request.URL.path error: &error];
67
62
if (!fileAttributes) {
68
- [delegate URLRequest: strongOp didCompleteWithError: error];
63
+ [delegate URLRequest: weakOp didCompleteWithError: error];
69
64
return ;
70
65
}
71
66
@@ -82,14 +77,14 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ
82
77
expectedContentLength: [fileAttributes[NSFileSize ] ?: @-1 integerValue ]
83
78
textEncodingName: nil ];
84
79
85
- [delegate URLRequest: strongOp didReceiveResponse: response];
80
+ [delegate URLRequest: weakOp didReceiveResponse: response];
86
81
87
82
// Load data
88
83
NSData *data = [NSData dataWithContentsOfURL: request.URL options: NSDataReadingMappedIfSafe error: &error];
89
84
if (data) {
90
- [delegate URLRequest: strongOp didReceiveData: data];
85
+ [delegate URLRequest: weakOp didReceiveData: data];
91
86
}
92
- [delegate URLRequest: strongOp didCompleteWithError: error];
87
+ [delegate URLRequest: weakOp didCompleteWithError: error];
93
88
}];
94
89
95
90
weakOp = op;
You can’t perform that action at this time.
0 commit comments