Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created January 16, 2020 18:56
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergLam/609e2dc76b9f321877f4fb7fe8e26fdf to your computer and use it in GitHub Desktop.
Save SergLam/609e2dc76b9f321877f4fb7fe8e26fdf to your computer and use it in GitHub Desktop.
Swift - check iOS app environment (debug OR TestFlight build) at runtime
import UIKit
extension UIApplication {
// MARK: Public
func isRunningInTestFlightEnvironment() -> Bool {
if isSimulator() {
return false
} else {
if isAppStoreReceiptSandbox() && !hasEmbeddedMobileProvision() {
return true
} else {
return false
}
}
}
func isRunningInAppStoreEnvironment() -> Bool {
if isSimulator(){
return false
} else {
if isAppStoreReceiptSandbox() || hasEmbeddedMobileProvision() {
return false
} else {
return true
}
}
}
// MARK: Private
private func hasEmbeddedMobileProvision() -> Bool {
guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else {
return true
}
return false
}
private func 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 func isSimulator() -> Bool {
#if arch(i386) || arch(x86_64)
return true
#else
return false
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment