Skip to content

Commit 560777f

Browse files
authored
Fix fireperf exception (#12991)
1 parent 7434377 commit 560777f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

FirebasePerformance/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- Fix Crash from InstrumentUploadTaskWithStreamedRequest (#12983).
3+
14
# 10.25.0
25
- [changed] Removed usages of user defaults API to eliminate required reason impact.
36

FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,15 @@ void InstrumentUploadTaskWithStreamedRequest(FPRNSURLSessionInstrument *instrume
482482
if (!strongInstrument) {
483483
ThrowExceptionBecauseInstrumentHasBeenDeallocated(selector, instrumentor.instrumentedClass);
484484
}
485-
typedef NSURLSessionUploadTask *(*OriginalImp)(id, SEL, NSURLRequest *);
486-
NSURLSessionUploadTask *uploadTask = ((OriginalImp)currentIMP)(session, selector, request);
485+
typedef NSURLSessionUploadTask *(*OriginalImp)(id, SEL, NSURLRequest *, NSData *);
486+
// To avoid a runtime warning in Xcode 15, the given `URLRequest`
487+
// should have a nil `HTTPBody`. To workaround this, the `HTTPBody` data is removed
488+
// and requestData is replaced with it, if it bodyData was `nil`.
489+
NSMutableURLRequest *requestWithoutHTTPBody = [request mutableCopy];
490+
NSData *requestData = requestWithoutHTTPBody.HTTPBody;
491+
requestWithoutHTTPBody.HTTPBody = nil;
492+
NSURLSessionUploadTask *uploadTask =
493+
((OriginalImp)currentIMP)(session, selector, request, requestData);
487494
if (uploadTask.originalRequest) {
488495
FPRNetworkTrace *trace =
489496
[[FPRNetworkTrace alloc] initWithURLRequest:uploadTask.originalRequest];

0 commit comments

Comments
 (0)