Skip to content

Commit

Permalink
use production firebase config only for app store installs (#74)
Browse files Browse the repository at this point in the history
* use production firebase config only for app store installs

* improve installation source readability

* replace jailbroken

* formatting

* privatize isJailbroken
  • Loading branch information
mike-dydx committed Aug 20, 2024
1 parent bf5581a commit df0a5af
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ public class FirebaseNotificationHandler: NotificationHandler {
if let token = token {
Console.shared.log("Firebase registration token: \(token)")
}
if !Installation.appStore {
switch Installation.source {
case .debug, .testFlight:
DebugSettings.shared?.debug?["push_token"] = token
case .appStore, .jailBroken:
break
}
}
}
Expand Down
28 changes: 12 additions & 16 deletions Shared/CommonAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ open class CommonAppDelegate: ParticlesAppDelegate {
Console.shared.log("injectFeatures")
injectFirebase()
let compositeFeatureFlags = CompositeFeatureFlagsProvider()
if !Installation.appStore {
switch Installation.source {
case .debug, .testFlight:
compositeFeatureFlags.local = FeatureFlagsStore.shared
case .appStore, .jailBroken:
break
}
compositeFeatureFlags.remote = FirebaseRunner.shared.enabled ? FirebaseFeatureFlagsProvider() : nil
FeatureService.shared = compositeFeatureFlags
Expand Down Expand Up @@ -76,16 +79,10 @@ open class CommonAppDelegate: ParticlesAppDelegate {
}

open func useProductionFirebase() -> Bool {
#if DEBUG
return false
#else
if !Installation.jailBroken {
return AbacusStateManager.shared.currentEnvironment == "1"
} else {
return false
}
// return Installation.appStore && !Installation.jailBroken
#endif
switch Installation.source {
case .debug, .testFlight, .jailBroken: return false
case .appStore: return true
}
}

open func injectFirebase() {
Expand All @@ -105,10 +102,11 @@ open class CommonAppDelegate: ParticlesAppDelegate {
open func injectAmplitude() {
Console.shared.log("injectAmplitude")
let apiKey: String?
if Installation.appStore && !Installation.jailBroken {
apiKey = CredientialConfig.shared.key(for: "amplitudeApiKey")
} else {
switch Installation.source {
case .jailBroken, .debug, .testFlight:
apiKey = CredientialConfig.shared.key(for: "amplitudeStagingApiKey")
case .appStore:
apiKey = CredientialConfig.shared.key(for: "amplitudeApiKey")
}
if let apiKey = apiKey, apiKey.isNotEmpty {
AmplitudeRunner.shared.apiKey = apiKey
Expand All @@ -118,7 +116,6 @@ open class CommonAppDelegate: ParticlesAppDelegate {

open func injectAttribution() {
Console.shared.log("injectAttribution")
// if Installation.appStore && !Installation.jailBroken {
if let devKey = CredientialConfig.shared.key(for: "appsFlyerDevKey"), devKey.isNotEmpty,
let appId = CredientialConfig.shared.key(for: "appsFlyerAppId"), appId.isNotEmpty {
AppsFlyerRunner.shared.devKey = devKey
Expand All @@ -127,7 +124,6 @@ open class CommonAppDelegate: ParticlesAppDelegate {
Attributer.shared?.launch()
add(tracking: AppsFlyerTracking())
}
// }
}

open func injectLocalNotifications() {
Expand Down
12 changes: 4 additions & 8 deletions Utilities/Utilities/_Error/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ public final class Console: NSObject, SingletonProtocol {
public static var shared: Console = Console()

private var visible: Bool = {
#if DEBUG
return true
#else
if Installation.appStore || Installation.jailBroken {
return false
}
return true
#endif
switch Installation.source {
case .debug, .testFlight: return true
case .appStore, .jailBroken: return false
}
}()

public func log(_ object: Any?) {
Expand Down
10 changes: 5 additions & 5 deletions Utilities/Utilities/_Utils/DebugEnabled.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public struct DebugEnabled {
public static let key = "debug.enabled"

public static var enabled: Bool {
#if DEBUG
true
#else
!Installation.appStore && UserDefaults.standard.bool(forKey: key)
#endif
switch Installation.source {
case .debug: return true
case .testFlight: return UserDefaults.standard.bool(forKey: key)
case .appStore, .jailBroken: return false
}
}
}
44 changes: 33 additions & 11 deletions Utilities/Utilities/_Utils/Installation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@
import Foundation

public class Installation {
public static var appStore: Bool = {
if let receipt: URL = Bundle.main.appStoreReceiptURL {
var error: NSError?
if (receipt as NSURL).checkResourceIsReachableAndReturnError(&error), error == nil {
return true
}
}
public enum Source {
case debug
case testFlight
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"

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

public static var jailBroken: Bool = {
#endif
}

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


public static var source: Source {
return .appStore
if isJailBroken {
return .jailBroken
} else if isDebug {
return .debug
} else if isTestFlight {
return .testFlight
} else {
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 @@ -57,9 +57,10 @@ public class CompositeFeatureFlagsProvider: NSObject & FeatureFlagsProtocol {
}

public func flag(feature: String?) -> Any? {
if Installation.appStore {
switch Installation.source {
case .appStore, .jailBroken, .testFlight:
return remote?.flag(feature: feature)
} else {
case .debug:
if let localFlag = local?.flag(feature: feature) {
return localFlag
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public final class AbacusStateManager: NSObject {
#endif
} else {
// Expose more options for Testflight build
deployment = Installation.appStore ? "MAINNET" : "TESTNET"
switch Installation.source {
case .appStore:
deployment = "MAINNET"
case .testFlight, .debug, .jailBroken:
deployment = "TESTNET"
}
appConfigs = AppConfigs.companion.forApp
}

Expand Down

0 comments on commit df0a5af

Please sign in to comment.