77
88import Combine
99import Foundation
10+ import OSLog
1011import SwiftUI
1112import UID2
1213
14+ extension RootViewModel {
15+ struct Configuration {
16+ let subscriptionID : String
17+ let appName : String
18+ let serverPublicKeyString : String
19+
20+ static func uid2( ) -> Self {
21+ self . init (
22+ subscriptionID: " toPh8vgJgt " ,
23+ appName: Bundle . main. bundleIdentifier!,
24+ // swiftlint:disable:next line_length
25+ serverPublicKeyString: " UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKAbPfOz7u25g1fL6riU7p2eeqhjmpALPeYoyjvZmZ1xM2NM8UeOmDZmCIBnKyRZ97pz5bMCjrs38WM22O7LJuw== "
26+ )
27+ }
28+
29+ static func euid( ) -> Self {
30+ self . init (
31+ subscriptionID: " w6yPQzN4dA " ,
32+ appName: Bundle . main. bundleIdentifier!,
33+ // swiftlint:disable:next line_length
34+ serverPublicKeyString: " EUID-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEH/k7HYGuWhjhCo8nXgj/ypClo5kek7uRKvzCGwj04Y1eXOWmHDOLAQVCPquZdfVVezIpABNAl9zvsSEC7g+ZGg== "
35+ )
36+ }
37+ }
38+ }
39+
1340@MainActor
14- class RootViewModel : ObservableObject {
15-
41+ final class RootViewModel : ObservableObject {
42+
43+ let isEUID : Bool
44+
1645 @Published private( set) var uid2Identity : UID2Identity ? {
1746 didSet {
1847 error = nil
@@ -25,19 +54,33 @@ class RootViewModel: ObservableObject {
2554
2655 /// `UID2Settings` must be configured prior to accessing the `UID2Manager` instance.
2756 /// Configuring them here makes it less likely that an access occurs before configuration.
28- private let manager : UID2Manager = {
57+ private let manager : UID2Manager
58+
59+ private let configuration : Configuration
60+
61+ private let log = OSLog ( subsystem: " com.uid2.UID2SDKDevelopmentApp " , category: " RootViewModel " )
62+
63+ init ( ) {
64+ isEUID = Bundle . main. object ( forInfoDictionaryKey: " UID2EnvironmentEUID " ) as? Bool ?? false
65+
2966 UID2Settings . shared. isLoggingEnabled = true
3067 // Only the development app should use the integration environment.
3168 // If you have copied the dev app for testing, you probably want to use the default
3269 // environment, which is production.
3370 if Bundle . main. bundleIdentifier == " com.uid2.UID2SDKDevelopmentApp " {
34- UID2Settings . shared. environment = . custom( url: URL ( string: " https://operator-integ.uidapi.com " ) !)
71+ UID2Settings . shared. euidEnvironment = . custom( url: URL ( string: " https://integ.euid.eu/v2 " ) !)
72+ UID2Settings . shared. uid2Environment = . custom( url: URL ( string: " https://operator-integ.uidapi.com " ) !)
3573 }
3674
37- return UID2Manager . shared
38- } ( )
39-
40- init ( ) {
75+ if isEUID {
76+ os_log ( " Configured for EUID " , log: log, type: . info)
77+ configuration = . euid( )
78+ manager = EUIDManager . shared
79+ } else {
80+ os_log ( " Configured for UID2 " , log: log, type: . info)
81+ configuration = . uid2( )
82+ manager = UID2Manager . shared
83+ }
4184 Task {
4285 for await state in await manager. stateValues ( ) {
4386 self . uid2Identity = state? . identity
@@ -130,17 +173,13 @@ class RootViewModel: ObservableObject {
130173 }
131174
132175 func clientSideGenerate( identity: IdentityType ) {
133- let subscriptionID = " toPh8vgJgt "
134- // swiftlint:disable:next line_length
135- let serverPublicKeyString = " UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKAbPfOz7u25g1fL6riU7p2eeqhjmpALPeYoyjvZmZ1xM2NM8UeOmDZmCIBnKyRZ97pz5bMCjrs38WM22O7LJuw== "
136-
137176 Task < Void , Never > {
138177 do {
139178 try await manager. generateIdentity (
140179 identity,
141- subscriptionID: subscriptionID,
142- serverPublicKey: serverPublicKeyString,
143- appName: Bundle . main . bundleIdentifier!
180+ subscriptionID: configuration . subscriptionID,
181+ serverPublicKey: configuration . serverPublicKeyString,
182+ appName: configuration . appName
144183 )
145184 } catch {
146185 self . error = error
0 commit comments