From 13aaaa6ae0cb04356fc4e2c9c673a67a8d7f9137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Thu, 1 Oct 2015 13:35:17 +0200 Subject: [PATCH] Move AppStore detection and adapt for TestFlight --- Classes/BITHockeyHelper.h | 4 ++++ Classes/BITHockeyHelper.m | 39 ++++++++++++++++++++++++++++++++++++++ Classes/BITHockeyManager.m | 15 ++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Classes/BITHockeyHelper.h b/Classes/BITHockeyHelper.h index abd44c3093..0bfb9df416 100644 --- a/Classes/BITHockeyHelper.h +++ b/Classes/BITHockeyHelper.h @@ -47,6 +47,10 @@ NSString *bit_UUID(void); NSString *bit_appAnonID(BOOL forceNewAnonID); BOOL bit_isPreiOS7Environment(void); BOOL bit_isPreiOS8Environment(void); +BOOL bit_isAppStoreReceiptSandbox(void); +BOOL bit_hasEmbeddedMobileProvision(void); +BOOL bit_isRunningInTestFlightEnvironment(void); +BOOL bit_isRunningInAppStoreEnvironment(void); BOOL bit_isRunningInAppExtension(void); #if !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnly) && !defined (HOCKEYSDK_CONFIGURATION_ReleaseCrashOnlyExtensions) diff --git a/Classes/BITHockeyHelper.m b/Classes/BITHockeyHelper.m index c18980bd77..57902821a2 100644 --- a/Classes/BITHockeyHelper.m +++ b/Classes/BITHockeyHelper.m @@ -271,6 +271,45 @@ BOOL bit_isPreiOS8Environment(void) { return isPreiOS8Environment; } +BOOL bit_isAppStoreReceiptSandbox(void) { +#if TARGET_IPHONE_SIMULATOR + return NO; +#else + NSURL *appStoreReceiptURL = NSBundle.mainBundle.appStoreReceiptURL; + NSString *appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent; + + BOOL isSandboxReceipt = [appStoreReceiptLastComponent isEqualToString:@"sandboxReceipt"]; + return isSandboxReceipt; +#endif +} + +BOOL bit_hasEmbeddedMobileProvision(void) { + BOOL hasEmbeddedMobileProvision = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]; + return hasEmbeddedMobileProvision; +} + +BOOL bit_isRunningInTestFlightEnvironment(void) { +#if TARGET_IPHONE_SIMULATOR + return NO; +#else + if (bit_isAppStoreReceiptSandbox() && !bit_hasEmbeddedMobileProvision()) { + return YES; + } + return NO; +#endif +} + +BOOL bit_isRunningInAppStoreEnvironment(void) { +#if TARGET_IPHONE_SIMULATOR + return NO; +#else + if (bit_isAppStoreReceiptSandbox() || bit_hasEmbeddedMobileProvision()) { + return NO; + } + return YES; +#endif +} + BOOL bit_isRunningInAppExtension(void) { static BOOL isRunningInAppExtension = NO; static dispatch_once_t checkAppExtension; diff --git a/Classes/BITHockeyManager.m b/Classes/BITHockeyManager.m index f50396b44c..655c46fa01 100644 --- a/Classes/BITHockeyManager.m +++ b/Classes/BITHockeyManager.m @@ -75,6 +75,15 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h @interface BITHockeyManager () +/** + Flag that determines whether the application is installed and running + from an App Store installation. + + Returns _YES_ if the app is installed and running from the App Store + Returns _NO_ if the app is installed via debug, ad-hoc or enterprise distribution + */ +@property (nonatomic, readonly, getter=isTestFlightEnvironment) BOOL testFlightEnvironment; + - (BOOL)shouldUseLiveIdentifier; @end @@ -156,6 +165,7 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h _enableStoreUpdateManager = NO; #endif + _testFlightEnvironment = NO; _appStoreEnvironment = NO; _startManagerIsInvoked = NO; _startUpdateManagerIsInvoked = NO; @@ -166,9 +176,12 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h #if !TARGET_IPHONE_SIMULATOR // check if we are really in an app store environment - if (![[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]) { + if (bit_isRunningInAppStoreEnvironment()) { _appStoreEnvironment = YES; } + if (bit_isRunningInTestFlightEnvironment()) { + _testFlightEnvironment = YES; + } #endif [self performSelector:@selector(validateStartManagerIsInvoked) withObject:nil afterDelay:0.0f];