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.

+3


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
{
#if TARGET_IPHONE_SIMULATOR
    return YES;
#else
    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;
#endif
}

      



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

+1


source







All Articles