Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active October 30, 2019 03:49
Show Gist options
  • Save steipete/7668246 to your computer and use it in GitHub Desktop.
Save steipete/7668246 to your computer and use it in GitHub Desktop.
Detect if you're currently running a development version or an App Store/Ad Hoc version.
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {
const char *bytes = [data bytes];
NSMutableString *profile = [[NSMutableString alloc] initWithCapacity:data.length];
for (NSUInteger i = 0; i < data.length; i++) {
[profile appendFormat:@"%c", bytes[i]];
}
// Look for debug value, if detected we're a development build.
NSString *cleared = [[profile componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] componentsJoinedByString:@""];
isDevelopment = [cleared rangeOfString:@"<key>get-task-allow</key><true/>"].length > 0;
}
});
return isDevelopment;
#endif
}
@jarnoh
Copy link

jarnoh commented Nov 4, 2014

I tried this snippet in a production app a while back, this snippet caused a crash on ~0.1% of users.

@ghazel
Copy link

ghazel commented Feb 10, 2015

What was the crash?

@loretoparisi
Copy link

To avoid crashes I suggest to check only

+ (BOOL)isDevelopmentBuild {
#if TARGET_IPHONE_SIMULATOR
    return YES;
#else
    static BOOL isDevelopment = NO;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // There is no provisioning profile in AppStore Apps.
        NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
        if (data) {
            isDevelopment=YES;
        }
    });
    return isDevelopment;
#endif
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment