Skip to content

Commit 98bd91f

Browse files
committed
Switchable Development Mode
- For TestFlight to approve the app the user has to login using a demo account. I have added a button that allows the user to switch to the development mode inside the login settings.
1 parent 2d0a91e commit 98bd91f

4 files changed

Lines changed: 41 additions & 10 deletions

File tree

iOSSC.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
"$(inherited)",
455455
"@executable_path/Frameworks",
456456
);
457-
MARKETING_VERSION = 0.2.3;
457+
MARKETING_VERSION = 0.2.4;
458458
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
459459
PRODUCT_NAME = "$(TARGET_NAME)";
460460
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -479,7 +479,7 @@
479479
"$(inherited)",
480480
"@executable_path/Frameworks",
481481
);
482-
MARKETING_VERSION = 0.2.3;
482+
MARKETING_VERSION = 0.2.4;
483483
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
484484
PRODUCT_NAME = "$(TARGET_NAME)";
485485
PROVISIONING_PROFILE_SPECIFIER = "";

iOSSC/Model/APIManager.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class APIManager: ObservableObject {
1818
@Published var data: ResponseData?
1919
@Published var loginState: LoginState = .loggedOut
2020

21-
private let environment: Environment
21+
private var environment: Environment
2222
private var username: String?
2323
private var password: String?
2424

@@ -188,6 +188,11 @@ class APIManager: ObservableObject {
188188
}
189189
}
190190

191+
func switchEnv() {
192+
logout()
193+
environment = environment == .production ? .development : .production
194+
}
195+
191196
private func getHeaders(_ username: String, _ password: String) -> HTTPHeaders {
192197
let credentialData = "\(username):\(password)".data(using: .utf8)
193198
guard let cred = credentialData else { return ["" : ""] }
@@ -209,6 +214,18 @@ class APIManager: ObservableObject {
209214
}
210215
}
211216

217+
var env: Environment {
218+
return environment
219+
}
220+
221+
var inProduction: Bool {
222+
return environment == .production
223+
}
224+
225+
var inDevelopment: Bool {
226+
return environment == .development
227+
}
228+
212229
/**
213230
Sets the environment the application should run in
214231
*/

iOSSC/View/LoginView.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,32 @@ struct LoginView: View {
8383
VStack {
8484
Text("Nur HTTPS erlaubt!")
8585
.foregroundColor(.white)
86+
87+
Button(devModeButtonText) {
88+
manager.switchEnv()
89+
}
90+
.foregroundColor(.hsd)
91+
.padding()
92+
8693
InputField(manager.baseUrl, text: $customUrl)
8794
}
8895
.padding(.bottom, 8)
8996
}
9097

91-
InputField("Benutzername", text: $username)
92-
.padding(.bottom, 8)
93-
InputField("Password", text: $password, isSecure: true)
98+
Group {
99+
InputField("Benutzername", text: $username)
100+
.padding(.bottom, 8)
101+
InputField("Password", text: $password, isSecure: true)
102+
}
103+
.disabled(manager.inDevelopment)
104+
.blur(radius: manager.inDevelopment ? 3 : 0)
94105
}
95106
}
96107

108+
private var devModeButtonText: String {
109+
return manager.inProduction ? "Aktiviere Entwickler Modus" : "Deaktiviere Entwickler Modus"
110+
}
111+
97112
private var footer: some View {
98113
VStack {
99114
Button("Login") {

iOSSC/iOSSCApp.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import SwiftUI
99
import SFSafeSymbols
1010

11-
let env: APIManager.Environment = .production
12-
1311
@main
1412
struct iOSSCApp: App {
1513

1614
@ObservedObject
17-
private var manager = APIManager(enviorment: env)
15+
private var manager = APIManager(enviorment: .production)
1816

1917
var body: some Scene {
2018
WindowGroup {
@@ -30,9 +28,10 @@ struct iOSSCApp: App {
3028
}
3129

3230
// Development Label
33-
if (env == .development) {
31+
if (manager.inDevelopment) {
3432
VStack {
3533
HStack {
34+
Spacer()
3635
Text("Development Mode")
3736
.foregroundColor(.red)
3837
.font(.caption)

0 commit comments

Comments
 (0)