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