-
-
Save songjiz/64ee6508b4b5cac71bb9c61a74a5e581 to your computer and use it in GitHub Desktop.
A Rails-like environment helper for iOS apps, from https://masilotti.com/rails-like-endpoint-switcher-for-ios-apps/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum Environment: String { | |
case development, staging, production | |
} | |
extension Environment { | |
static var current: Environment { | |
if isAppStore { | |
return .production | |
} else if isTestFlight { | |
return .staging | |
} | |
return .development | |
} | |
static var isTestFlight: Bool { | |
if isSimulator { | |
return false | |
} else { | |
if isAppStoreReceiptSandbox, !hasEmbeddedMobileProvision { | |
return true | |
} else { | |
return false | |
} | |
} | |
} | |
static var isAppStore: Bool { | |
if isSimulator { | |
return false | |
} else { | |
if isAppStoreReceiptSandbox || hasEmbeddedMobileProvision { | |
return false | |
} else { | |
return true | |
} | |
} | |
} | |
var isDevelopment: Bool { self == .development } | |
var isStaging: Bool { self == .staging } | |
var isProduction: Bool { self == .production } | |
private static var hasEmbeddedMobileProvision: Bool { | |
guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else { | |
return true | |
} | |
return false | |
} | |
private static var isAppStoreReceiptSandbox: Bool { | |
if isSimulator { | |
return false | |
} else { | |
guard let url = Bundle.main.appStoreReceiptURL else { | |
return false | |
} | |
guard url.lastPathComponent == "sandboxReceipt" else { | |
return false | |
} | |
return true | |
} | |
} | |
private static var isSimulator: Bool { | |
#if targetEnvironment(simulator) | |
return true | |
#else | |
return false | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment