Define the target configuration Type of configuration from the static library

How can I get the build configuration type from a static library (debug or release)?
We usually use it #ifdef DEBUG

, but in this case it won't work as this check is compile time and our static library is already compiled.


source to share

1 answer

If you just want to know if the application was compiled during debug or production (AdHoc equals production), you can use the following method, which can be called in a static library:

+ (BOOL)isDevelopmentBuild
    return YES;
    BOOL isDevelopment = NO;

    // 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 in a development build.
        NSString *cleared = [[profile componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] componentsJoinedByString:@""];
        isDevelopment = ([cleared rangeOfString:@"<key>get-task-allow</key><true/>"].length > 0);

    return isDevelopment;


Note that it will return YES if the app is in development mode.



All Articles