Check whether app is built in debug or release mode

Currently, if as a library author you are shipping dependencies as code, you can use the #if DEBUG preprocessor check to execute logic based on whether app is being built for Debug or Release.

My concern is more about the approach that should be taken when distributing frameworks/xcframeworks. One approach I am thinking of using is checking the presence of {CFBundleName}.debug.dylib in the main bundle. Is this approach reliable? Do you suggest any other approach?

Is this approach reliable?

No. You can disable preview support using a build settings, even in the Debug build configuration. Indeed, that’s something I do all the time.

Lemme confirm I understand your requirements:

  • You’re working on a framework.
  • You want to create an XCFramemwork from that.
  • And give that XCFramework to other developers.
  • And then inside that framework you want to check whether the host app was built with the Debug build configuration.

Is that right?

If so, to what end?

And are you sure that you want to check the build configuration? A lot of the time it’s not the build configuration that matters, it’s the way that the app was signed. Or the way that’s it’s run (from Xcode or like a user would). And those questions have different answers.

Is this iOS? Or macOS? Or both?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for the replay  @DTS Engineer. You are right on my requirement, currently I am looking for iOS but I would be happy with a solution that works across apple platforms as well.

If so, to what end?

To answer your query on why I want to detect debug build I won't be able to share my exact use-case but I will share a parallel use-case that currently Apple uses:

Currently Apple allows developers to send push notifications to iOS with APNS. From what I understand, APNS exposes sandbox and production environments which are controlled with aps-environment entitlement. Since, Apple controls the tooling side of iOS development, they can inject entitlement based on the provisioning profile.

I want to achieve something similar to this where the REST API domain used by my framework is decided based on either provisioning profile or build type.

A lot of the time it’s not the build configuration that matters, it’s the way that the app was signed. Or the way that’s it’s run (from Xcode or like a user would). And those questions have different answers.

I think more appropriate solution for me will be deciding based on the way app was signed, something like what Apple does for APNS. I did look into it but was unable to find any way to parse the included provisioning profile. Would appreciate any help with this.

Check whether app is built in debug or release mode
 
 
Q