com*_*ial 110 ios testflight
是否有可能在运行时检测到已通过TestFlight Beta(通过iTunes Connect提交)与App Store安装了应用程序?您可以提交单个应用包,并通过它们提供.是否有可以检测安装方式的API?或收据是否包含允许确定此信息的信息?
com*_*ial 110
对于通过TestFlight Beta安装的应用程序,收据文件的命名StoreKit\sandboxReceipt与通常相同StoreKit\receipt.使用[NSBundle appStoreReceiptURL]您可以在URL的末尾查找sandboxReceipt.
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSString *receiptURLString = [receiptURL path];
BOOL isRunningTestFlightBeta = ([receiptURLString rangeOfString:@"sandboxReceipt"].location != NSNotFound);
Run Code Online (Sandbox Code Playgroud)
请注意,这sandboxReceipt也是在本地运行构建时以及在模拟器中运行构建时的接收文件的名称.
小智 60
根据组合的答案,我创建了以下SWIFT助手类.使用此类,您可以确定它是debug,testflight还是appstore构建.
enum AppConfiguration {
case Debug
case TestFlight
case AppStore
}
struct Config {
// This is private because the use of 'appConfiguration' is preferred.
private static let isTestFlight = NSBundle.mainBundle().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
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们在项目中使用这些方法为每个环境提供不同的跟踪ID或连接字符串:
func getURL(path: String) -> String {
switch (Config.appConfiguration) {
case .Debug:
return host + "://" + debugBaseUrl + path
default:
return host + "://" + baseUrl + path
}
}
Run Code Online (Sandbox Code Playgroud)
要么:
static var trackingKey: String {
switch (Config.appConfiguration) {
case .Debug:
return debugKey
case .TestFlight:
return testflightKey
default:
return appstoreKey
}
}
Run Code Online (Sandbox Code Playgroud)
更新05-02-2016: 使用像#if DEBUG这样的预处理器宏的先决条件是设置一些Swift编译器自定义标志.本答案中的更多信息:https://stackoverflow.com/a/24112024/639227
Ser*_*nko 27
现代Swift版本,它考虑了模拟器(基于已接受的答案):
private func isSimulatorOrTestFlight() -> Bool {
guard let path = Bundle.main.appStoreReceiptURL?.path else {
return false
}
return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
}
Run Code Online (Sandbox Code Playgroud)
wzb*_*zon 11
我Bundle+isProduction在 Swift 5.2 上使用扩展:
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
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
if Bundle.main.isProduction {
// do something
}
Run Code Online (Sandbox Code Playgroud)
这不再起作用。使用其他方法。
这也适用:
if NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") != nil {
// TestFlight
} else {
// App Store (and Apple reviewers too)
}
Run Code Online (Sandbox Code Playgroud)
在检测到是否从苹果的Testflight下载了iOS应用程序中找到
| 归档时间: |
|
| 查看次数: |
17953 次 |
| 最近记录: |