adobe / aepsdk-core-ios

Adobe Experience Platform Mobile Core SDK in Swift
Apache License 2.0
25 stars 41 forks source link

getMobileCarrierName spams logs due to call to non-functional serviceSubscriberCellularProviders #1055

Open rnapier opened 4 months ago

rnapier commented 4 months ago

Prerequisites

Bug summary

Since iOS 16, it is no longer possible to get the mobile carrier information. The required functions are deprecated without replacement, and the OS will return a stub response with name "--" on device and nil on simulator. This is slow and spams the logs with errors such as:

2024-07-04 14:02:52.249495-0400 ...[56386:3273558] [Client] Updating selectors failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated: failed at lookup with error 3 - No such process.}

This call should be avoided on iOS 16+.

Environment

OS: iOS 16+ SDK: AEP 5.2.0 IDE: Xcode 15.4

Steps to reproduce

Call getMobileCarrierName. Observe logs for com.apple.commcenter.coretelephony.xpc errors.

Current behavior

Spams logs with errors and returns "--" or nil.

Expected behavior

Should not attempt to access CoreTelephony on iOS 16+.

Anything else?

Something like the following would address the problem:

diff --git a/AEPServices/Sources/ApplicationSystemInfoService.swift b/AEPServices/Sources/ApplicationSystemInfoService.swift
index fbaa615..9bcaeae 100644
--- a/AEPServices/Sources/ApplicationSystemInfoService.swift
+++ b/AEPServices/Sources/ApplicationSystemInfoService.swift
@@ -106,6 +106,11 @@ class ApplicationSystemInfoService: SystemInfoService {
         #if targetEnvironment(macCatalyst) || os(tvOS)
             return "unknown"
         #else
+        if #available(iOS 16, *) {
+            // Since iOS 16, `serviceSubscriberCellularProviders` is deprecated without replacement.
+            // `carrierName` always returns "--" and may throw errors into the logs.
+            return "--"
+        } else {
             let networkInfo = CTTelephonyNetworkInfo()
             let carrier: CTCarrier?
             if #available(iOS 12, *) {
@@ -115,6 +120,7 @@ class ApplicationSystemInfoService: SystemInfoService {
             }

             return carrier?.carrierName
+        }
         #endif
     }
cdhoffmann commented 3 months ago

@rnapier Thanks for reporting this. We will be marking this as an enhancement because we have to discuss with the team if using an availability macro is sufficient of if we should look at a more robust e2e approach to this. Will keep you posted on the ticket once we pick it up.