diff --git a/Examples/SampleObjC-iOS/SampleObjC-iOS.xcodeproj/project.pbxproj b/Examples/SampleObjC-iOS/SampleObjC-iOS.xcodeproj/project.pbxproj index 3b86bba7..06b9feec 100644 --- a/Examples/SampleObjC-iOS/SampleObjC-iOS.xcodeproj/project.pbxproj +++ b/Examples/SampleObjC-iOS/SampleObjC-iOS.xcodeproj/project.pbxproj @@ -370,7 +370,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = Z6DGB573C6; + DEVELOPMENT_TEAM = WPX9KRKA8B; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "SampleObjC-iOS/Info.plist"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; @@ -403,7 +403,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = Z6DGB573C6; + DEVELOPMENT_TEAM = WPX9KRKA8B; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "SampleObjC-iOS/Info.plist"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; diff --git a/Sources/Classes/Helpers/Platforms/Vendors/AppleUtils.swift b/Sources/Classes/Helpers/Platforms/Vendors/AppleUtils.swift index b1750149..ae15a9e9 100644 --- a/Sources/Classes/Helpers/Platforms/Vendors/AppleUtils.swift +++ b/Sources/Classes/Helpers/Platforms/Vendors/AppleUtils.swift @@ -16,6 +16,9 @@ import UIKit #if !os(tvOS) import WebKit #endif +#if os(iOS) +import CoreTelephony +#endif internal class PhoneVendor: Vendor { private let device = UIDevice.current @@ -25,15 +28,15 @@ internal class PhoneVendor: Vendor { } override var type: String { - #if os(iOS) +#if os(iOS) return "ios" - #elseif os(tvOS) +#elseif os(tvOS) return "tvos" - #elseif targetEnvironment(macCatalyst) +#elseif targetEnvironment(macCatalyst) return "macos" - #else +#else return "unknown" - #endif +#endif } override var model: String { @@ -71,6 +74,51 @@ internal class PhoneVendor: Vendor { return [RSiOSLifecycleMonitor(), RSDeviceTokenPlugin()] } + override var carrier: String { +#if os(iOS) + return retrieveCarrierNames() ?? "unavailable"; +#else + return "unavailable" +#endif + + } + +#if os(iOS) + func retrieveCarrierNames() -> String? { + let systemVersion = UIDevice.current.systemVersion + let versionComponents = systemVersion.split(separator: ".").compactMap { Int($0) } + if versionComponents.count > 0 { + let majorVersion = versionComponents[0] + + if majorVersion >= 16 { + RSClient.rsLog(message: "Unable to retrieve carrier name as the iOS version is >= 16", logLevel: .warning) + return nil + } else if majorVersion >= 12 && majorVersion < 16 { + let networkInfo = CTTelephonyNetworkInfo() + var carrierNames: [String] = [] + + if let carriers = networkInfo.serviceSubscriberCellularProviders?.values { + for carrierObj in carriers { + if let carrierName = carrierObj.carrierName, carrierName != "--" { + carrierNames.append(carrierName) + } + } + } + if(!carrierNames.isEmpty) { + let formattedCarrierNames = carrierNames.joined(separator: ", ") + return formattedCarrierNames + } + } else { + let networkInfo = CTTelephonyNetworkInfo() + if let carrier = networkInfo.subscriberCellularProvider?.carrierName, carrier != "--" { + return carrier + } + } + } + return nil + } +#endif + private func deviceModel() -> String { var name: [Int32] = [CTL_HW, HW_MACHINE] var size: Int = 2 @@ -126,7 +174,7 @@ internal class WatchVendor: Vendor { let screenSize = device.screenBounds.size return ScreenSize(width: Double(screenSize.width), height: Double(screenSize.height), density: device.screenScale) } - + override var connection: ConnectionStatus { let path = NWPathMonitor().currentPath let interfaces = path.availableInterfaces @@ -161,7 +209,7 @@ internal class WatchVendor: Vendor { let model = String(cString: hw_machine) return model } - + } #endif @@ -213,7 +261,7 @@ internal class MacVendor: Vendor { let screenSize = NSScreen.main?.frame.size ?? CGSize(width: 0, height: 0) return ScreenSize(width: Double(screenSize.width), height: Double(screenSize.height), density: Double(NSScreen.main?.backingScaleFactor ?? 0)) } - + override var connection: ConnectionStatus { return connectionStatus() } @@ -232,34 +280,34 @@ internal class MacVendor: Vendor { } return identifier } - + private func macAddress(bsd: String) -> String? { let MAC_ADDRESS_LENGTH = 6 let separator = ":" - + var length: size_t = 0 var buffer: [CChar] - + let bsdIndex = Int32(if_nametoindex(bsd)) if bsdIndex == 0 { return nil } let bsdData = Data(bsd.utf8) var managementInfoBase = [CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, bsdIndex] - + if sysctl(&managementInfoBase, 6, nil, &length, nil, 0) < 0 { return nil } - + buffer = [CChar](unsafeUninitializedCapacity: length, initializingWith: {buffer, initializedCount in for x in 0...stride + 1 let rangeOfToken = infoData[indexAfterMsghdr...].range(of: bsdData)! @@ -285,20 +333,20 @@ extension ConnectionStatus { init(reachabilityFlags flags: SCNetworkReachabilityFlags) { let connectionRequired = flags.contains(.connectionRequired) let isReachable = flags.contains(.reachable) - #if !os(macOS) +#if !os(macOS) let isCellular = flags.contains(.isWWAN) - #endif - +#endif + if !connectionRequired && isReachable { - #if !os(macOS) +#if !os(macOS) if isCellular { self = .online(.cellular) } else { self = .online(.wifi) } - #else +#else self = .online(.wifi) - #endif +#endif } else { self = .offline @@ -310,20 +358,20 @@ internal func connectionStatus() -> ConnectionStatus { var zeroAddress = sockaddr_in() zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress)) zeroAddress.sin_family = sa_family_t(AF_INET) - + guard let defaultRouteReachability = (withUnsafePointer(to: &zeroAddress) { $0.withMemoryRebound(to: sockaddr.self, capacity: 1) { zeroSockAddress in SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress) } }) else { - return .unknown + return .unknown } - + var flags: SCNetworkReachabilityFlags = [] if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) { return .unknown } - + return ConnectionStatus(reachabilityFlags: flags) }