检测TestFlight?

我宁愿使用TestFlight与App Store相同的构buildconfiguration。 有没有办法在运行时检测应用程序是否已经通过TestFlight或App Store安装? (我的想法是,如果没有通过App Store安装,我只会打电话给takeOff 。)

我想避免在App Store中使用TestFlight来保护我们用户的隐私,并且避免在这里讨论的networking的潜在脱轨问题。

我相信这是足够接近重复的检查,如果iOS应用程序是活在应用程序商店 ,这可以closures。

您可以通过检查是否存在embedded.mobileprovision来确定您的应用是否通过app store分发。 这个文件只包含在adhoc构build中。 因此,如果仅通过TestFlight或HockeyApp分发构build,而不是构build商店,则它必须是TestFlight或HockeyApp构build。

喜欢这个:

 if ([[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]) { // not from app store } else { // from app store } 

这项技术来自HockeyApp SDK 。

要确定Swift中的Debug,TestFlight或AppStore部署:

  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 } 

完整的源代码和示例: https : //stackoverflow.com/a/33830605/639227

你可以做一些类似于文档为setDeviceIdenifier调用提供的东西:

SDK文档的Betatesting和版本差异部分build议在[TestFlight takeOff:@"api-token"];之前放置以下[TestFlight takeOff:@"api-token"];

 #define TESTING 1 #ifdef TESTING [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; #endif 

当发布应用程序时,build议您注释掉 #define TESTING 1行,以便后续对setDeviceIdentifier调用将被跳过。 您的代码将如下所示:

 //#define TESTING 1 #ifdef TESTING [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; #endif 

你的解决scheme

为了防止被调用,你可以把它放在setDeviceIdentifier下面,并注释掉#define TESTING 1 ,就像上面的build议一样。 哪个会给你:

 //#define TESTING 1 #ifdef TESTING [TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]]; [TestFlight takeOff:@"api-token"]; #endif 

HTH


如果你不熟悉,你可以在这里阅读更多关于#ifdef 信息 。

这是一篇博客文章,向您展示如何添加除Debug和Release(例如Beta)之外的其他configuration。

在添加Betaconfiguration之后,您将创build另一个项目scheme。 然后编辑这个新的scheme。 在部分存档下,请select使用testing版configuration。 然后你使用这个scheme来存档Testflight和之前的应用程序商店的scheme。