Skip to content

Commit

Permalink
Safer check of .appStore vs .testFlight build, and enables TESTFLIGHT…
Browse files Browse the repository at this point in the history
… deployment (#76)
  • Loading branch information
johnqh authored Jan 30, 2024
1 parent 40ec2a6 commit 12d2e50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
26 changes: 18 additions & 8 deletions Utilities/Utilities/_Utils/Installation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ public class Installation {
case appStore
case jailBroken // potentially side-loaded
}

// This is private because the use of 'appConfiguration' is preferred.
private static let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"


private static let isAppStore = {
// Keep this code for reference. In case "sandboxReceipt" changes in later iOS
if let receipt: URL = Bundle.main.appStoreReceiptURL {
var error: NSError?
if (receipt as NSURL).checkResourceIsReachableAndReturnError(&error), error == nil {
return true
}
}
return false
}()

// This can be used to add debug statements.
static var isDebug: Bool {
#if DEBUG
return true
return true
#else
return false
return false
#endif
}

private static var isJailBroken: Bool = {
#if targetEnvironment(simulator)
return false
Expand All @@ -54,9 +65,8 @@ public class Installation {
}
#endif
}()

public static var source: Source {
return .appStore
if isJailBroken {
return .jailBroken
} else if isDebug {
Expand All @@ -67,7 +77,7 @@ public class Installation {
return .appStore
}
}

public static var isSimulator: Bool = {
#if targetEnvironment(simulator)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public class CompositeFeatureFlagsProvider: NSObject & FeatureFlagsProtocol {

public func flag(feature: String?) -> Any? {
switch Installation.source {
case .appStore, .jailBroken, .testFlight:
case .appStore, .jailBroken:
return remote?.flag(feature: feature)
case .debug:
case .debug, .testFlight:
if let localFlag = local?.flag(feature: feature) {
return localFlag
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ public final class AbacusStateManager: NSObject {
switch Installation.source {
case .appStore:
deployment = "MAINNET"
case .testFlight, .debug, .jailBroken:
case .debug, .jailBroken:
deployment = "TESTNET"
case .testFlight:
deployment = "TESTFLIGHT"
}
appConfigs = AppConfigs.companion.forApp
}
Expand Down

0 comments on commit 12d2e50

Please sign in to comment.