Skip to content

Commit

Permalink
Switchable Development Mode
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
KuhlTime committed Nov 14, 2021
1 parent 2d0a91e commit 98bd91f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions iOSSC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.3;
MARKETING_VERSION = 0.2.4;
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -479,7 +479,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.3;
MARKETING_VERSION = 0.2.4;
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
19 changes: 18 additions & 1 deletion iOSSC/Model/APIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class APIManager: ObservableObject {
@Published var data: ResponseData?
@Published var loginState: LoginState = .loggedOut

private let environment: Environment
private var environment: Environment
private var username: String?
private var password: String?

Expand Down Expand Up @@ -188,6 +188,11 @@ class APIManager: ObservableObject {
}
}

func switchEnv() {
logout()
environment = environment == .production ? .development : .production
}

private func getHeaders(_ username: String, _ password: String) -> HTTPHeaders {
let credentialData = "\(username):\(password)".data(using: .utf8)
guard let cred = credentialData else { return ["" : ""] }
Expand All @@ -209,6 +214,18 @@ class APIManager: ObservableObject {
}
}

var env: Environment {
return environment
}

var inProduction: Bool {
return environment == .production
}

var inDevelopment: Bool {
return environment == .development
}

/**
Sets the environment the application should run in
*/
Expand Down
21 changes: 18 additions & 3 deletions iOSSC/View/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,32 @@ struct LoginView: View {
VStack {
Text("Nur HTTPS erlaubt!")
.foregroundColor(.white)

Button(devModeButtonText) {
manager.switchEnv()
}
.foregroundColor(.hsd)
.padding()

InputField(manager.baseUrl, text: $customUrl)
}
.padding(.bottom, 8)
}

InputField("Benutzername", text: $username)
.padding(.bottom, 8)
InputField("Password", text: $password, isSecure: true)
Group {
InputField("Benutzername", text: $username)
.padding(.bottom, 8)
InputField("Password", text: $password, isSecure: true)
}
.disabled(manager.inDevelopment)
.blur(radius: manager.inDevelopment ? 3 : 0)
}
}

private var devModeButtonText: String {
return manager.inProduction ? "Aktiviere Entwickler Modus" : "Deaktiviere Entwickler Modus"
}

private var footer: some View {
VStack {
Button("Login") {
Expand Down
7 changes: 3 additions & 4 deletions iOSSC/iOSSCApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import SwiftUI
import SFSafeSymbols

let env: APIManager.Environment = .production

@main
struct iOSSCApp: App {

@ObservedObject
private var manager = APIManager(enviorment: env)
private var manager = APIManager(enviorment: .production)

var body: some Scene {
WindowGroup {
Expand All @@ -30,9 +28,10 @@ struct iOSSCApp: App {
}

// Development Label
if (env == .development) {
if (manager.inDevelopment) {
VStack {
HStack {
Spacer()
Text("Development Mode")
.foregroundColor(.red)
.font(.caption)
Expand Down

0 comments on commit 98bd91f

Please sign in to comment.