Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
Address Firebase Performance issues with Xcode 15
### Description

In the Xcode 15 beta0, FirebasePerformance has two build warnings:

![Screenshot 2023-06-05 at 3 32 49 PM](https://github.com/firebase/firebase-ios-sdk/assets/73870/19e918a6-a8e4-467a-bda2-e7b8a5436168)

One unit test failure:
![Screenshot 2023-06-05 at 3 33 43 PM](https://github.com/firebase/firebase-ios-sdk/assets/73870/58beec69-cc20-40ed-b2a5-37f8e174a276)

and one unit test crash in testCopySelectorFromClassThatModifies:
![Screenshot 2023-06-05 at 3 34 21 PM](https://github.com/firebase/firebase-ios-sdk/assets/73870/f4cd9c29-17bb-4658-8a38-2f8481e64c63)




### Reproducing the issue

Build and run unit tests with Xcode 15 beta0

### Firebase SDK Version

10.11.0

### Xcode Version

15.0-beta

### Installation Method

Swift Package Manager

### Firebase Product(s)

Performance

### Targeted Platforms

iOS

### Relevant Log Output

_No response_

### If using Swift Package Manager, the project's Package.resolved

<!--- Look below for instructions on how to share your Package.resolved. --->

<details>
<summary>Expand <code>Package.resolved</code> snippet</summary>
<br>

```json

Replace this line with the contents of your Package.resolved.

```

</details>


### If using CocoaPods, the project's Podfile.lock

<!--- Look below for instructions on how to share your Podfile.lock. --->

<details>
<summary>Expand <code>Podfile.lock</code> snippet</summary>
<br>

```yml

Replace this line with the contents of your Podfile.lock!

```

</details>



Discussion / hints:

Fix patch:
diff --git a/FirebasePerformance/CHANGELOG.md b/FirebasePerformance/CHANGELOG.md
index 7a4c05dd4fe..4443842b7ad 100644
--- a/FirebasePerformance/CHANGELOG.md
+++ b/FirebasePerformance/CHANGELOG.md
@@ -1,3 +1,7 @@
+# Unreleased
+- [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.
+
 # 10.11.0
 - [fixed] Fixed a bug to disable data collection if the data collection was disabled before Firebase application was configured.
 
diff --git a/FirebasePerformance/Sources/FPRDataUtils.h b/FirebasePerformance/Sources/FPRDataUtils.h
index 1874196ae37..f7a6557f51c 100644
--- a/FirebasePerformance/Sources/FPRDataUtils.h
+++ b/FirebasePerformance/Sources/FPRDataUtils.h
@@ -46,11 +46,3 @@ FOUNDATION_EXTERN NSString *FPRValidatedAttributeValue(NSString *value);
  *  @return The unchanged url string or a truncated version if the length goes beyond the limit.
  */
 FOUNDATION_EXTERN NSString *FPRTruncatedURLString(NSString *URLString);
-
-/** Ensures proper length and numerals and returns a concatenated version if valid.
- *
- *  @param mcc 3 digit MCC code.
- *  @param mnc 2 or 3 digit MNC code.
- *  @return Concatenated mcc and mnc codes if valid. Otherwise nil.
- */
-FOUNDATION_EXTERN NSString *FPRValidatedMccMnc(NSString *mcc, NSString *mnc);
diff --git a/FirebasePerformance/Sources/FPRDataUtils.m b/FirebasePerformance/Sources/FPRDataUtils.m
index bdbe2cf4331..fe3a7cf13ed 100644
--- a/FirebasePerformance/Sources/FPRDataUtils.m
+++ b/FirebasePerformance/Sources/FPRDataUtils.m
@@ -124,16 +124,3 @@
   }
   return truncatedURLString;
 }
-
-NSString *FPRValidatedMccMnc(NSString *mcc, NSString *mnc) {
-  if ([mcc length] != 3 || [mnc length] < 2 || [mnc length] > 3) return nil;
-
-  static NSCharacterSet *notDigits;
-  static dispatch_once_t token;
-  dispatch_once(&token, ^{
-    notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
-  });
-  NSString *mccMnc = [mcc stringByAppendingString:mnc];
-  if ([mccMnc rangeOfCharacterFromSet:notDigits].location != NSNotFound) return nil;
-  return mccMnc;
-}
diff --git a/FirebasePerformance/Sources/FPRNanoPbUtils.m b/FirebasePerformance/Sources/FPRNanoPbUtils.m
index 39d12d14df4..199eec92dfa 100644
--- a/FirebasePerformance/Sources/FPRNanoPbUtils.m
+++ b/FirebasePerformance/Sources/FPRNanoPbUtils.m
@@ -129,9 +129,28 @@ static firebase_perf_v1_NetworkConnectionInfo_MobileSubtype FPRCellularNetworkTy
     };
   });
 
-  NSString *networkString = FPRNetworkInfo().currentRadioAccessTechnology;
-  NSNumber *cellularNetworkType = cellularNetworkToMobileSubtype[networkString];
-  return cellularNetworkType.intValue;
+  // Use recent APIs for iOS 12 and above and older APIs for before.
+  if (@available(iOS 12, *)) {
+    NSDictionary<NSString *, NSString *> *radioAccessors =
+        FPRNetworkInfo().serviceCurrentRadioAccessTechnology;
+    if (radioAccessors.count > 0) {
+      NSString *networkString = [radioAccessors.allValues objectAtIndex:0];
+      NSNumber *cellularNetworkType = cellularNetworkToMobileSubtype[networkString];
+      return cellularNetworkType.intValue;
+    }
+  } else {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+    NSString *networkString = FPRNetworkInfo().currentRadioAccessTechnology;
+
+#pragma clang diagnostic pop
+
+    NSNumber *cellularNetworkType = cellularNetworkToMobileSubtype[networkString];
+    return cellularNetworkType.intValue;
+  }
+
+  return firebase_perf_v1_NetworkConnectionInfo_MobileSubtype_UNKNOWN_MOBILE_SUBTYPE;
 }
 #endif
 
@@ -218,12 +237,6 @@ firebase_perf_v1_ApplicationInfo FPRGetApplicationInfoMessage(void) {
   iosAppInfo.has_network_connection_info = true;
   iosAppInfo.network_connection_info.has_network_type = true;
 #ifdef TARGET_HAS_MOBILE_CONNECTIVITY
-  CTTelephonyNetworkInfo *networkInfo = FPRNetworkInfo();
-  CTCarrier *provider = networkInfo.subscriberCellularProvider;
-  NSString *mccMnc = FPRValidatedMccMnc(provider.mobileCountryCode, provider.mobileNetworkCode);
-  if (mccMnc) {
-    iosAppInfo.mcc_mnc = FPREncodeString(mccMnc);
-  }
   if (iosAppInfo.network_connection_info.network_type ==
       firebase_perf_v1_NetworkConnectionInfo_NetworkType_MOBILE) {
     iosAppInfo.network_connection_info.mobile_subtype = FPRCellularNetworkType();
diff --git a/FirebasePerformance/Tests/Unit/FPRNanoPbUtilsTest.m b/FirebasePerformance/Tests/Unit/FPRNanoPbUtilsTest.m
index 6c21a54cd0e..08b17bc1a18 100644
--- a/FirebasePerformance/Tests/Unit/FPRNanoPbUtilsTest.m
+++ b/FirebasePerformance/Tests/Unit/FPRNanoPbUtilsTest.m
@@ -95,30 +95,6 @@ - (void)testApplicationInfoMessageWithAttributes {
   [performance removeAttribute:@"foo2"];
 }
 
-/** Tests if mccMnc validation is catching non numerals. */
-- (void)testMccMncOnlyHasNumbers {
-  NSString *mccMnc = FPRValidatedMccMnc(@"123", @"MKV");
-  XCTAssertNil(mccMnc);
-  mccMnc = FPRValidatedMccMnc(@"ABC", @"123");
-  XCTAssertNil(mccMnc);
-}
-
-/** Tests if mccMnc validation is working. */
-- (void)testMccMnc {
-  NSString *mccMnc = FPRValidatedMccMnc(@"123", @"22");
-  XCTAssertNotNil(mccMnc);
-  mccMnc = FPRValidatedMccMnc(@"123", @"223");
-  XCTAssertNotNil(mccMnc);
-}
-
-/** Tests if mccMnc validation catches improper lengths. */
-- (void)testMccMncLength {
-  NSString *mccMnc = FPRValidatedMccMnc(@"12", @"22");
-  XCTAssertNil(mccMnc);
-  mccMnc = FPRValidatedMccMnc(@"123", @"2");
-  XCTAssertNil(mccMnc);
-}
-
 /** Validates that a valid FIRTrace object to firebase_perf_v1_TraceMetric conversion is successful.
  */
 - (void)testTraceMetricMessageCreation {
diff --git a/FirebasePerformance/Tests/Unit/FPRNetworkTraceTest.m b/FirebasePerformance/Tests/Unit/FPRNetworkTraceTest.m
index b260f95b4bc..6cfbd3e2b03 100644
--- a/FirebasePerformance/Tests/Unit/FPRNetworkTraceTest.m
+++ b/FirebasePerformance/Tests/Unit/FPRNetworkTraceTest.m
@@ -433,7 +433,7 @@ - (void)testTrimmedURLForShortLengthURLs {
   NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URL];
   FPRNetworkTrace *networkTrace = [[FPRNetworkTrace alloc] initWithURLRequest:URLRequest];
   XCTAssertNotNil(networkTrace);
-  XCTAssertEqual(networkTrace.URLRequest.URL.absoluteString, urlString);
+  XCTAssertEqualObjects(networkTrace.URLRequest.URL.absoluteString, urlString);
 }
 
 /** Validates that every trace contains a session Id. */


Test patch: