From c3fb18db920da5225a5883d65d022869e79dd7e4 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 Sep 2023 09:40:24 -0700 Subject: [PATCH 1/2] Fix Xcode 15 runtime warning --- FirebasePerformance/CHANGELOG.md | 3 +++ .../Instrumentation/Network/FPRNSURLSessionInstrument.m | 6 +++++- 2 files changed, 8 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..35183baa13b 100644 --- a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m +++ b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m @@ -405,8 +405,12 @@ 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. + NSMutableURLRequest *requestWithoutHTTPBody = [request mutableCopy]; + requestWithoutHTTPBody.HTTPBody = nil; NSURLSessionUploadTask *uploadTask = - ((OriginalImp)currentIMP)(session, selector, request, bodyData); + ((OriginalImp)currentIMP)(session, selector, requestWithoutHTTPBody, bodyData); if (uploadTask.originalRequest) { FPRNetworkTrace *trace = [[FPRNetworkTrace alloc] initWithURLRequest:uploadTask.originalRequest]; From 7f84596e77cc786c381480d54e901dc56f9f60b1 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 Sep 2023 12:01:33 -0700 Subject: [PATCH 2/2] Address review feedback --- .../Instrumentation/Network/FPRNSURLSessionInstrument.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m index 35183baa13b..32b2efc2f02 100644 --- a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m +++ b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m @@ -406,11 +406,13 @@ void InstrumentUploadTaskWithRequestFromData(FPRNSURLSessionInstrument *instrume } 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. + // 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, requestWithoutHTTPBody, bodyData); + ((OriginalImp)currentIMP)(session, selector, requestWithoutHTTPBody, requestData); if (uploadTask.originalRequest) { FPRNetworkTrace *trace = [[FPRNetworkTrace alloc] initWithURLRequest:uploadTask.originalRequest];