是否有可能在运行时检测到应用程序已通过TestFlight测试版(通过iTunes连接提交)与应用商店进行了安装?您可以提交单个应用程序包,并通过这两个应用程序包都可以使用。是否有API可以检测它的安装方式?或者,收据中是否包含可以确定这一点的信息?
发布于 2014-09-30 13:47:52
对于通过TestFlight测试版安装的应用程序,回执文件名为StoreKit\sandboxReceipt,而不是通常的StoreKit\receipt。使用[NSBundle appStoreReceiptURL],您可以在URL的末尾查找sandboxReceipt。
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSString *receiptURLString = [receiptURL path];
BOOL isRunningTestFlightBeta = ([receiptURLString rangeOfString:@"sandboxReceipt"].location != NSNotFound);请注意,当在本地运行构建时,以及对于在模拟器中运行的构建,sandboxReceipt也是接收文件的名称。
发布于 2016-08-17 05:10:26
现代Swift版本,用于模拟器(基于公认的答案):
private func isSimulatorOrTestFlight() -> Bool {
guard let path = Bundle.main.appStoreReceiptURL?.path else {
return false
}
return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
}发布于 2020-04-04 17:28:26
我在Swift 5.2上使用扩展Bundle+isProduction:
import Foundation
extension Bundle {
var isProduction: Bool {
#if DEBUG
return false
#else
guard let path = self.appStoreReceiptURL?.path else {
return true
}
return !path.contains("sandboxReceipt")
#endif
}
}然后:
if Bundle.main.isProduction {
// do something
}https://stackoverflow.com/questions/26081543
复制相似问题