Conditional compilation behavior for native iOS plug-ins
Learn how to use conditional compilation to support different project types in your native source code plug-in.
Read time 2 minutesLast updated 13 days ago
Learn about the conditions you can check at different stages of build and runtime to create a generic plug-in that works across different targets.
Use conditional logic to create a generic plug-in that works across different targets. You can add checks in both native and C# code at different stages of the build and runtime process.
The following table outlines the conditions you can check at each stage:
Build stage | Conditions and usage |
|---|---|
| Xcode project generation | Automatic plug-in integration: When using the plug-in Inspector, configure platform-specific settings to check for the Platform, SDK version, Architecture, and Project type, and use Define Constraints to check for the Unity version. Manual plug-in file injection at post process with the PBXProject API: Use PostProcessBuildAttribute with the PBXProject API to add plug-ins based on Unity versions. You can check for:
|
| Xcode project compilation | In native code (Swift or Objective-C), you can check for:
|
| Application runtime | In native code, Swift or Objective-C, you can check for:
|
You can use preprocessor directives, such as , in both Swift and Objective-C to adjust behavior based on the target platform, architecture, or SDK version.
#ifUnity's generated Xcode project can be one of two types: Swift or Objective-C. To distinguish between these types in your native code, use the preprocessor macro.
UNITY_XCODE_PROJECT_TYPE_SWIFT