diff --git a/Modules/Sources/NetworkingCore/ApplicationPassword/ApplicationPasswordUseCase.swift b/Modules/Sources/NetworkingCore/ApplicationPassword/ApplicationPasswordUseCase.swift index 3f45858302e..1ebfce2da6a 100644 --- a/Modules/Sources/NetworkingCore/ApplicationPassword/ApplicationPasswordUseCase.swift +++ b/Modules/Sources/NetworkingCore/ApplicationPassword/ApplicationPasswordUseCase.swift @@ -2,6 +2,10 @@ import Foundation import enum Alamofire.AFError import KeychainAccess +#if canImport(UIKit) +import UIKit +#endif + public enum ApplicationPasswordUseCaseError: Error { case duplicateName case applicationPasswordsDisabled @@ -29,25 +33,6 @@ public protocol ApplicationPasswordUseCase { func deletePassword() async throws } -/// A wrapper for the `UIDevice` `model` and `identifierForVendor` properties. -/// -/// This is necessary because `UIDevice` is part of UIKit which we cannot use when targeting watchOS. -/// So, to keep this package compatible with watchOS, we need to abstract UIKit away and delegate it to the consumers to provide us -/// with the device information. -/// -/// This approach is feasible because only the `applicationPasswordName` method in -/// `DefaultApplicationPasswordUseCase` needs access to the information and watchOS does not need to create application -/// passwords. We can therefore pass a `nil` value to it to satisfy the compilation without issues for the user experience. -public struct DeviceModelIdentifierInfo { - let model: String - let identifierForVendor: String - - public init(model: String, identifierForVendor: String) { - self.model = model - self.identifierForVendor = identifierForVendor - } -} - final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase { /// Site Address /// @@ -65,31 +50,27 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase /// private let storage: ApplicationPasswordStorage - private let deviceModelIdentifierInfo: DeviceModelIdentifierInfo? - /// Used to name the password in wpadmin. /// private var applicationPasswordName: String { - get { - guard let deviceModelIdentifierInfo else { - return "" // This is not needed on watchOS as the watch does not create application passwords. - } - - let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown" - return "\(bundleIdentifier).ios-app-client.\(deviceModelIdentifierInfo.model).\(deviceModelIdentifierInfo.identifierForVendor)" - } +#if !os(watchOS) + let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown" + let model = UIDevice.current.model + let identifierForVendor = UIDevice.current.identifierForVendor?.uuidString ?? "" + return "\(bundleIdentifier).ios-app-client.\(model).\(identifierForVendor)" +#else + fatalError("Unexpected error: Application password should not be generated through watch app") +#endif } public init(username: String, password: String, siteAddress: String, - deviceModelIdentifierInfo: DeviceModelIdentifierInfo? = nil, network: Network? = nil, keychain: Keychain = Keychain(service: WooConstants.keychainServiceName)) throws { self.siteAddress = siteAddress self.username = username self.storage = ApplicationPasswordStorage(keychain: keychain) - self.deviceModelIdentifierInfo = deviceModelIdentifierInfo if let network { self.network = network @@ -154,7 +135,7 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase if let uuidFromLocalPassword { return uuidFromLocalPassword } else { - return try await self.fetchUUIDForApplicationPassword(await applicationPasswordName) + return try await self.fetchUUIDForApplicationPassword(applicationPasswordName) } }() try await deleteApplicationPassword(uuidToBeDeleted) @@ -167,7 +148,7 @@ private extension DefaultApplicationPasswordUseCase { /// - Returns: Generated `ApplicationPassword` /// func createApplicationPassword() async throws -> ApplicationPassword { - let passwordName = await applicationPasswordName + let passwordName = applicationPasswordName let parameters = [ParameterKey.name: passwordName] let request = RESTRequest(siteURL: siteAddress, method: .post, path: Path.applicationPasswords, parameters: parameters) diff --git a/WooCommerce/Classes/Authentication/AuthenticationManager.swift b/WooCommerce/Classes/Authentication/AuthenticationManager.swift index 7fd88172de4..e173b589914 100644 --- a/WooCommerce/Classes/Authentication/AuthenticationManager.swift +++ b/WooCommerce/Classes/Authentication/AuthenticationManager.swift @@ -752,8 +752,7 @@ private extension AuthenticationManager { guard let useCase = try? DefaultApplicationPasswordUseCase( username: siteCredentials.username, password: siteCredentials.password, - siteAddress: siteCredentials.siteURL, - deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo + siteAddress: siteCredentials.siteURL ) else { return assertionFailure("⛔️ Error creating application password use case") } diff --git a/WooCommerce/Classes/System/SessionManager.swift b/WooCommerce/Classes/System/SessionManager.swift index 74c6e52df4f..bfc2fd4259e 100644 --- a/WooCommerce/Classes/System/SessionManager.swift +++ b/WooCommerce/Classes/System/SessionManager.swift @@ -234,7 +234,6 @@ final class SessionManager: SessionManagerProtocol { return try? DefaultApplicationPasswordUseCase(username: username, password: password, siteAddress: siteAddress, - deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo, keychain: keychain) case let .applicationPassword(_, _, siteAddress): return OneTimeApplicationPasswordUseCase(siteAddress: siteAddress, keychain: keychain) diff --git a/WooCommerce/Classes/System/UIDevice+DeviceModelIdentifierInfo.swift b/WooCommerce/Classes/System/UIDevice+DeviceModelIdentifierInfo.swift deleted file mode 100644 index a23e6dfa5aa..00000000000 --- a/WooCommerce/Classes/System/UIDevice+DeviceModelIdentifierInfo.swift +++ /dev/null @@ -1,12 +0,0 @@ -import Networking -import UIKit - -extension UIDevice { - - var deviceModelIdentifierInfo: DeviceModelIdentifierInfo { - DeviceModelIdentifierInfo( - model: model, - identifierForVendor: identifierForVendor?.uuidString ?? "" - ) - } -} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index d065e0c6ac9..c88cc00c989 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -1307,7 +1307,6 @@ 3F58701F281B947E004F7556 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F58701E281B947E004F7556 /* Main.storyboard */; }; 3F587021281B9494004F7556 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F587020281B9494004F7556 /* LaunchScreen.storyboard */; }; 3F587026281B9C19004F7556 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3F587028281B9C19004F7556 /* InfoPlist.strings */; }; - 3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */; }; 4506BD712461965300FE6377 /* ProductVisibilityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4506BD6F2461965300FE6377 /* ProductVisibilityViewController.swift */; }; 4506BD722461965300FE6377 /* ProductVisibilityViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4506BD702461965300FE6377 /* ProductVisibilityViewController.xib */; }; 4508BF622660E34A00707869 /* ShippingLabelCarrierAndRatesTopBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4508BF612660E34A00707869 /* ShippingLabelCarrierAndRatesTopBanner.swift */; }; @@ -4480,7 +4479,6 @@ 3F587037281B9C50004F7556 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; 3F587038281B9C52004F7556 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = ""; }; 3F64F76C2C06A3A50085DEEF /* WooCommerce.release-alpha.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "WooCommerce.release-alpha.xcconfig"; sourceTree = ""; }; - 3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+DeviceModelIdentifierInfo.swift"; sourceTree = ""; }; 3FF314EF26FC784A0012E68E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 4506BD6F2461965300FE6377 /* ProductVisibilityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVisibilityViewController.swift; sourceTree = ""; }; 4506BD702461965300FE6377 /* ProductVisibilityViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProductVisibilityViewController.xib; sourceTree = ""; }; @@ -11066,7 +11064,6 @@ DE6906E627D74A1900735E3B /* WooSplitViewController.swift */, 26A7C8782BE91F3D00382627 /* WatchDependenciesSynchronizer.swift */, 26B249702BEC801400730730 /* WatchDependencies.swift */, - 3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */, ); path = System; sourceTree = ""; @@ -16257,7 +16254,6 @@ 205B7ECD2C19FD2F00D14A36 /* PointOfSaleCardPresentPaymentDisplayReaderMessageMessageViewModel.swift in Sources */, 2DB877522E25466C0001B175 /* ShippingItemRowAccessibility.swift in Sources */, DEF8CF1F29AC870A00800A60 /* WPComEmailLoginViewModel.swift in Sources */, - 3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */, 74A33D8021C3F234009E25DE /* LicensesViewController.swift in Sources */, 454453CA27566CDE00464AC5 /* HubMenuViewModel.swift in Sources */, 934CB123224EAB150005CCB9 /* main.swift in Sources */, diff --git a/config/Version.Public.xcconfig b/config/Version.Public.xcconfig index 48d463c6ca5..a6dc153d207 100644 --- a/config/Version.Public.xcconfig +++ b/config/Version.Public.xcconfig @@ -1,4 +1,4 @@ CURRENT_PROJECT_VERSION = $VERSION_LONG MARKETING_VERSION = $VERSION_SHORT VERSION_LONG = 23.0.0.0 -VERSION_SHORT = 23.0 +VERSION_SHORT = 23.0 \ No newline at end of file