Created
March 1, 2019 18:55
-
-
Save rkotzy/35c54e6d44f4b427ac03712688a4de84 to your computer and use it in GitHub Desktop.
Determine what environment your iOS app is running in
This file contains 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 AppConfiguration : String { | |
case debug = "debug" | |
case testFlight = "testFlight" | |
case appStore = "appStore" | |
} | |
struct Config { | |
// 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 | |
#endif | |
} | |
static var appConfiguration: AppConfiguration { | |
if isDebug { | |
return .debug | |
} else if isTestFlight { | |
return .testFlight | |
} else { | |
return .appStore | |
} | |
} | |
} | |
// // Sample usage | |
// if Config.appConfiguration != .appStore { | |
// // this is a test user | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment