Last active
September 16, 2020 10:33
-
-
Save mvarie/63455babc2d0480858da to your computer and use it in GitHub Desktop.
Detects whether we're running in a Simulator, TestFlight Beta or App Store build
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
// | |
// WhereAmIRunning.swift | |
// https://gist.github.com/mvarie/63455babc2d0480858da | |
// | |
// ### Detects whether we're running in a Simulator, TestFlight Beta or App Store build ### | |
// | |
// Based on https://github.com/bitstadium/HockeySDK-iOS/blob/develop/Classes/BITHockeyHelper.m | |
// Inspired by http://stackoverflow.com/questions/18282326/how-can-i-detect-if-the-currently-running-app-was-installed-from-the-app-store | |
// Created by marcantonio on 04/11/15. | |
// | |
import Foundation | |
class WhereAmIRunning { | |
// 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{ | |
if let _ = NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") { | |
return true | |
} | |
return false | |
} | |
private func isAppStoreReceiptSandbox() -> Bool { | |
if isSimulator() { | |
return false | |
} else { | |
if let appStoreReceiptURL = NSBundle.mainBundle().appStoreReceiptURL, | |
let appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent | |
where appStoreReceiptLastComponent == "sandboxReceipt" { | |
return true | |
} | |
return false | |
} | |
} | |
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
Very nice! Was this verified with xcode7/iOS9?