Created
January 16, 2020 18:56
-
-
Save SergLam/609e2dc76b9f321877f4fb7fe8e26fdf to your computer and use it in GitHub Desktop.
Swift - check iOS app environment (debug OR TestFlight build) at runtime
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 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