Skip to content

Commit 8a78a70

Browse files
committed
Fix crash on watch app when authenticated with site credentials
1 parent 84f6b7d commit 8a78a70

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Modules/Sources/NetworkingCore/ApplicationPassword/ApplicationPasswordUseCase.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import enum Alamofire.AFError
33
import struct Alamofire.HTTPMethod
44
import KeychainAccess
55

6-
#if canImport(UIKit)
6+
#if !os(watchOS)
77
import UIKit
8+
#else
9+
import WatchKit
810
#endif
911

1012
public enum ApplicationPasswordUseCaseError: Error {
@@ -148,13 +150,16 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase
148150
private extension DefaultApplicationPasswordUseCase {
149151
/// Helper method to create password name from device
150152
static func createPasswordName() -> String {
151-
#if !os(watchOS)
152153
let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown"
154+
#if !os(watchOS)
153155
let model = UIDevice.current.model
154156
let identifierForVendor = UIDevice.current.identifierForVendor?.uuidString ?? ""
155157
return "\(bundleIdentifier).ios-app-client.\(model).\(identifierForVendor)"
156158
#else
157-
fatalError("Unexpected error: Application password should not be generated through watch app")
159+
let model = WKInterfaceDevice.current().model
160+
let identifierForVendor =
161+
WKInterfaceDevice.current().identifierForVendor?.uuidString ?? ""
162+
return "\(bundleIdentifier).watch-app-client.\(model).\(identifierForVendor)"
158163
#endif
159164
}
160165

0 commit comments

Comments
 (0)