2

On more than one occasion, I have accidentally changed the deployment target of my Xcode project to something I don't want. The latest time, I found out because a customer wasn't seeing my app. Is there a way to put something into my code somewhere to assert the value of the deployment target? I think I would be much less likely to change that by mistake.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323

2 Answers2

6

You can check your deployment target version via __IPHONE_OS_VERSION_MIN_REQUIRED macro and compare it to some sdk version, e.g. to make sure that your deployment target is 4.0 put the following lines somewhere:

#if  __IPHONE_OS_VERSION_MIN_REQUIRED != __IPHONE_4_0

#error wrong deployment target - should be 4.0

#endif 
Vladimir
  • 170,431
  • 36
  • 387
  • 313
1

Add a New Run Script Build Phase to your target and put this script inside:

DEPLOYMENT_TARGET_VALID=`expr ${IPHONEOS_DEPLOYMENT_TARGET} \>= "4.0"`;
if [ $DEPLOYMENT_TARGET_VALID = 1 ]; then
    echo "Deployment target ($IPHONEOS_DEPLOYMENT_TARGET) is too high."
    exit 1
fi;

Here, build will fail if the deployment target is set to 4.0 or higher.

Jilouc
  • 12,684
  • 4
  • 46
  • 43