如何从静态库(调试或发布)获取构建配置类型?
通常我们使用#ifdef DEBUG
但在这种情况下它不起作用,因为这个检查是编译时间,我们的静态库已经编译。
答案 0 :(得分:1)
如果您只想知道应用程序是在调试或生产中编译的(AdHoc等于生产),您可以使用以下方法,可以在静态库中调用:
+ (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
}
请注意,如果应用处于开发模式,它将返回YES。