-
Notifications
You must be signed in to change notification settings - Fork 5
SDKS-4916 Fix swift build failures — platform bump and if canImport guards #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,17 @@ | |
| // HardwareCollector.swift | ||
| // DeviceProfile | ||
| // | ||
| // Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| // Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved. | ||
| // | ||
| // This software may be modified and distributed under the terms | ||
| // of the MIT license. See the LICENSE file for details. | ||
| // | ||
|
|
||
| import Foundation | ||
| import UIKit | ||
| import AVFoundation | ||
| #if canImport(UIKit) | ||
| import UIKit | ||
| #endif | ||
|
|
||
| // MARK: - HardwareCollector | ||
|
|
||
|
|
@@ -93,14 +95,18 @@ public struct HardwareInfo: Codable, Sendable { | |
| /// - Values represent logical screen dimensions | ||
| @MainActor | ||
| private static func getDisplayInfo() -> [String: Int] { | ||
| #if canImport(UIKit) | ||
| let screenBounds = UIScreen.main.bounds | ||
| let isPortrait = UIDevice.current.orientation.isPortrait | ||
|
|
||
| return [ | ||
| "width": Int(screenBounds.width), | ||
| "height": Int(screenBounds.height), | ||
| "orientation": isPortrait ? 1 : 0 | ||
| ] | ||
| #else | ||
| return [:] | ||
| #endif | ||
| } | ||
|
|
||
| /// Retrieves camera system information | ||
|
|
@@ -119,6 +125,7 @@ public struct HardwareInfo: Codable, Sendable { | |
| /// - May return 0 if camera access is restricted | ||
| /// - Includes specialty cameras (telephoto, ultra-wide, etc.) | ||
| private static func getCameraInfo() -> [String: Int] { | ||
| #if canImport(UIKit) | ||
| let discoverySession = AVCaptureDevice.DiscoverySession( | ||
| deviceTypes: [ | ||
| .builtInTelephotoCamera, | ||
|
|
@@ -128,8 +135,11 @@ public struct HardwareInfo: Codable, Sendable { | |
| mediaType: .video, | ||
| position: .unspecified | ||
| ) | ||
|
|
||
| let cameraCount = discoverySession.devices.count | ||
| return ["numberOfCameras": cameraCount] | ||
| #else | ||
| return [:] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the display info fallback above — macOS is a build-only target so the empty return is intentional. Worth adding the same comment here for consistency: #else
// macOS: build target only for 3rd-party library compatibility — not a supported runtime platform
return [:]
#endif |
||
| #endif | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,17 @@ | |
| // PlatformCollector.swift | ||
| // DeviceProfile | ||
| // | ||
| // Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| // Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved. | ||
| // | ||
| // This software may be modified and distributed under the terms | ||
| // of the MIT license. See the LICENSE file for details. | ||
| // | ||
|
|
||
| import Foundation | ||
| import UIKit | ||
| import PingTamperDetector | ||
| #if canImport(UIKit) | ||
| import UIKit | ||
| #endif | ||
|
|
||
| // MARK: - PlatformCollector | ||
|
|
||
|
|
@@ -72,15 +74,22 @@ public struct PlatformInfo: Codable, Sendable { | |
|
|
||
| /// Initializes platform information by collecting system details | ||
| init() async { | ||
| #if canImport(UIKit) | ||
| self.platform = await UIDevice.current.systemName | ||
| self.version = await UIDevice.current.systemVersion | ||
| self.device = await UIDevice.current.model | ||
| self.deviceName = await UIDevice.current.name | ||
| #else | ||
| self.platform = "macOS" | ||
| self.version = ProcessInfo.processInfo.operatingSystemVersionString | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
let v = ProcessInfo.processInfo.operatingSystemVersion
self.version = "\(v.majorVersion).\(v.minorVersion).\(v.patchVersion)" |
||
| self.device = "Mac" | ||
| self.deviceName = Host.current().localizedName ?? "Mac" | ||
| #endif | ||
| self.model = Self.getDeviceModel() | ||
| self.brand = "Apple" | ||
| self.locale = Locale.current.language.languageCode?.identifier | ||
| self.timeZone = TimeZone.current.identifier | ||
|
|
||
| self.jailBreakScore = await TamperDetector().analyze() | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // TelephonyCollector.swift | ||
| // DeviceProfile | ||
| // | ||
| // Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| // Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved. | ||
| // | ||
| // This software may be modified and distributed under the terms | ||
| // of the MIT license. See the LICENSE file for details. | ||
|
|
@@ -61,17 +61,18 @@ | |
| /// - Selects the primary or most complete carrier information | ||
| /// - Prioritizes carriers with complete information | ||
| init() { | ||
| #if canImport(UIKit) | ||
| let networkInfo = CTTelephonyNetworkInfo() | ||
|
|
||
| var selectedCarrier: (carrierName: String?, isoCountryCode: String?)? | ||
|
|
||
| // Check for available cellular service providers | ||
| if let providers = networkInfo.serviceSubscriberCellularProviders, | ||
| !providers.isEmpty { | ||
|
|
||
| // Extract carrier information from all providers | ||
| let carriers = providers.map { | ||
| (carrierName: $0.value.carrierName, isoCountryCode: $0.value.isoCountryCode) | ||
|
Check warning on line 75 in DeviceProfile/DeviceProfile/Collectors/TelephonyCollector.swift
|
||
| } | ||
|
|
||
| // Select the best carrier using custom sorting logic | ||
|
|
@@ -86,6 +87,10 @@ | |
| self.carrierName = DeviceProfileConstants.unknown | ||
| self.networkCountryIso = DeviceProfileConstants.unknown | ||
| } | ||
| #else | ||
| self.carrierName = DeviceProfileConstants.unknown | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since macOS is a build-only target and this code won't run in production, returning #else
// macOS: build target only — telephony not available on this platform
self.carrierName = DeviceProfileConstants.unknown
self.networkCountryIso = DeviceProfileConstants.unknown
#endif |
||
| self.networkCountryIso = DeviceProfileConstants.unknown | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,27 +249,40 @@ public class LocationManager: NSObject, ObservableObject, @unchecked Sendable { | |
| } | ||
|
|
||
| // Handle different authorization states | ||
| switch await authorizationStatus { | ||
| case .authorizedAlways, .authorizedWhenInUse: | ||
| // Already authorized, fetch location | ||
| let currentStatus = await authorizationStatus | ||
| let isAuthorized: Bool | ||
| #if canImport(UIKit) | ||
| isAuthorized = (currentStatus == .authorizedAlways || currentStatus == .authorizedWhenInUse) | ||
| #else | ||
| isAuthorized = (currentStatus == .authorizedAlways) | ||
| #endif | ||
| if isAuthorized { | ||
| return try await fetchLocationWithAuthorization() | ||
|
|
||
| } | ||
|
|
||
| switch currentStatus { | ||
| case .notDetermined: | ||
| // Need to request authorization first | ||
| let status = try await requestAuthorizationIfNeeded() | ||
| if status == .authorizedAlways || status == .authorizedWhenInUse { | ||
| let statusAuthorized: Bool | ||
| #if canImport(UIKit) | ||
| statusAuthorized = (status == .authorizedAlways || status == .authorizedWhenInUse) | ||
| #else | ||
| statusAuthorized = (status == .authorizedAlways) | ||
| #endif | ||
| if statusAuthorized { | ||
| return try await fetchLocationWithAuthorization() | ||
| } else { | ||
| throw authorizationErrorForStatus(status) | ||
| } | ||
|
|
||
| case .denied: | ||
| throw LocationError.authorizationDenied | ||
|
|
||
| case .restricted: | ||
| throw LocationError.authorizationRestricted | ||
| @unknown default: | ||
|
|
||
| default: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code used @unknown default:
throw LocationError.authorizationDenied |
||
| throw LocationError.authorizationDenied | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,7 @@ open class IdpCollector: NSObject, Collector, ContinueNodeAware, RequestIntercep | |
| /// - url: The URL for the IdP authentication. | ||
| /// - Returns: A Result of type Bool or An IdpExceptions error. | ||
| public func fallbackToBrowserHandler(callbackURLScheme: String? = nil, url: URL) async -> Result<Bool, IdpExceptions> { | ||
| #if canImport(UIKit) | ||
| let urlScheme: String | ||
| if let customScheme = callbackURLScheme { | ||
| urlScheme = customScheme | ||
|
|
@@ -200,6 +201,9 @@ open class IdpCollector: NSObject, Collector, ContinueNodeAware, RequestIntercep | |
| } catch { | ||
| return .failure(.idpCanceledException(message: error.localizedDescription)) | ||
| } | ||
| #else | ||
| return .failure(.illegalStateException(message: "Browser authentication is not supported on this platform")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since macOS is a build-only target and browser-based IdP is iOS-only, returning a failure here is correct and intentional. Worth adding a comment so it's obvious this isn't a gap to fill: #else
// macOS: build target only — browser-based IdP authentication requires UIKit and is not a supported use case
return .failure(.illegalStateException(message: "Browser authentication is not supported on this platform"))
#endif |
||
| #endif | ||
| } | ||
|
|
||
| /// Authorizes the IdP | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macOS
#elsepath returns[:](empty dictionary) for display info. Since macOS is a build-only target for 3rd-party library compatibility and this code won't run in production, the empty return is fine — but a comment would help future readers distinguish intent from omission: