How can I get the build configuration type from a static library (debug or release)?
Normally we use #ifdef DEBUG but in this case it will not work, because this check is compile time and our static library is already compiled.
-
I'm not quite sure I follow - are you trying to determine how the static library was built? What config type the app using the library is being run under?bplattenburg– bplattenburg2015-05-04 14:37:40 +00:00Commented May 4, 2015 at 14:37
-
No. I want to know what config type the app using itselfarturdev– arturdev2015-05-04 14:41:07 +00:00Commented May 4, 2015 at 14:41
-
I don't think you're able to do that, as it would not be set at the time your code is compiled. I'm curious if there is another way to solve your initial problem - maybe have 2 versions of the library and link the appropriate one in the app?bplattenburg– bplattenburg2015-05-04 18:33:52 +00:00Commented May 4, 2015 at 18:33
-
My goal is to determine the build type of the app and send it to the server...arturdev– arturdev2015-05-04 18:41:39 +00:00Commented May 4, 2015 at 18:41
-
Ok, so couldn't you make a method that takes it in as a parameter to the library, then use #ifdef etc. to set that from the app? I'm assuming are writing both piecesbplattenburg– bplattenburg2015-05-04 20:47:47 +00:00Commented May 4, 2015 at 20:47
Add a comment
|
1 Answer
If you just want to know if the app was compiled in debug or production (AdHoc equals production), you can use the following method, which can be called within the 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
}
Notice it will return YES if the app is in development mode.
12 Comments
arturdev
Well, your answer is useful, but actually I want to know the build type of the app (debug or release), and doesn't matter is it running on a simulator or on a device. See screenshot: oi59.tinypic.com/atvlm9.jpg
Asaf
The simulator is just a specific check in order to avoids unnecessary code. It returns Yes if it's in development mode, otherwise No. Please try it in your code and let me know if it works for you.
Asaf
Just to clarify - if you check this method one real device in development mode, it will return YES.
arturdev
Seems it works on the device. But what about simulator?
Asaf
Simulator will always return YES cause you can't really install a release version on it (as far as I know).
|