From d14db425f687f968d57a7913135e35ce51292008 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 Sep 2023 14:10:41 -0700 Subject: [PATCH] Fix Xcode 15 runtime warning (#11825) --- FirebasePerformance/CHANGELOG.md | 3 +++ .../Instrumentation/Network/FPRNSURLSessionInstrument.m | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/FirebasePerformance/CHANGELOG.md b/FirebasePerformance/CHANGELOG.md index 58972852a61..2acbb91fb87 100644 --- a/FirebasePerformance/CHANGELOG.md +++ b/FirebasePerformance/CHANGELOG.md @@ -1,3 +1,6 @@ +# 10.16.0 +- [fixed] Fix Xcode 15 runtime warning (#11821). + # 10.12.0 - [fixed] Make Firebase performance compatible with Xcode15. - [changed] Removed the capability to access Carrier information of the device since that API is deprecated by Apple. diff --git a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m index 1b5d8232261..32b2efc2f02 100644 --- a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m +++ b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m @@ -405,8 +405,14 @@ void InstrumentUploadTaskWithRequestFromData(FPRNSURLSessionInstrument *instrume ThrowExceptionBecauseInstrumentHasBeenDeallocated(selector, instrumentor.instrumentedClass); } typedef NSURLSessionUploadTask *(*OriginalImp)(id, SEL, NSURLRequest *, NSData *); + // To avoid a runtime warning in Xcode 15, the given `URLRequest` + // should have a nil `HTTPBody`. To workaround this, the `HTTPBody` data is removed + // and requestData is replaced with it, if it bodyData was `nil`. + NSMutableURLRequest *requestWithoutHTTPBody = [request mutableCopy]; + NSData *requestData = bodyData ?: requestWithoutHTTPBody.HTTPBody; + requestWithoutHTTPBody.HTTPBody = nil; NSURLSessionUploadTask *uploadTask = - ((OriginalImp)currentIMP)(session, selector, request, bodyData); + ((OriginalImp)currentIMP)(session, selector, requestWithoutHTTPBody, requestData); if (uploadTask.originalRequest) { FPRNetworkTrace *trace = [[FPRNetworkTrace alloc] initWithURLRequest:uploadTask.originalRequest];