6

I'm using this tutorial to create a simple Settings Bundle in my app. The thing is that I want to hide the settings entirely in the release version and I cannot find a way to do it. I've read this question but it's still not clear to me.

Thanks in advance

I manage to accomplish this removing the Settings.bundle from target and adding this script to Build Phase:

if [ ${CONFIGURATION} == "Debug" ]; then
cp -r ${PROJECT_DIR}/HotelZilla/Classes/Settings/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
fi

But there's still a problem. If I remove the app then launch it in Release Scheme mode, the settings bundle doesn't appear. Then, I change into Debug Scheme and rebuild, the settings appear but, if then I switch again to Release, the settings are still there, so it seems that if I add a Setting to the Release app I can never delete the bundle again. Is that right?

Community
  • 1
  • 1
Chompas
  • 553
  • 8
  • 19

2 Answers2

9

If you're using a settings bundle for your settings, you need to exclude it from the build process for your app in the release configuration. A #ifdef DEBUG macro will only help you for code that you want to exclude from compilation - it won't help excluding a settings bundle.

You need to add a build phase to include/exclude your settings bundle based on the build configuration you're using. Check out How can I conditionally include a file based on build configuration in Xcode? for help with doing this.

Community
  • 1
  • 1
rickerbh
  • 9,731
  • 1
  • 31
  • 35
  • It worked. But I'm having a problem. I removed the Settings Bundle from target and used the script I added above in my question. The problem is that, if I build in Debug and then in Release, the Settings Bundle doesn't dissapear so if I make a mistake and release that into production I'll never be able to remove the settings bundle again? – Chompas Jan 15 '13 at 18:31
  • 1
    Building to the simulator doesn't remove files that were previously in the build from the simulator. This also applies to device builds on the device. However, that only affects the run not the build itself — builds for different configuration are stored in different folders within ~/Library/Developer/Xcode/DerivedData//Build/Products/. So this extra file won't appear in any archive you build. Store submissions are based on the archives. – Steven Fisher Jan 15 '13 at 18:55
  • You could also have a step in the build script to remove the file based on the build configuration. That will solve your simulator issue. – rickerbh Jan 15 '13 at 22:02
3

This can be done by running a script.

  • Choose Project

  • Choose Target

  • Switch to Build Phases Tab

  • Add Build Phase (+) Button

  • Choose Add Run Script

Add Script:

if [ "${CONFIGURATION}" == "Debug" ]; then
cp -r "${PROJECT_DIR}/${PRODUCT_NAME}/Settings/Settings_Debug.bundle/Root.plist" "${PROJECT_DIR}/${PRODUCT_NAME}/Settings.bundle/Root.plist"
echo "Debug settings bundle copied"
else
cp -r "${PROJECT_DIR}/${PRODUCT_NAME}/Settings/Settings_Release.bundle/Root.plist" "${PROJECT_DIR}/${PRODUCT_NAME}/Settings.bundle/Root.plist"
echo "Release settings bundle copied"
fi

NB: You need to create 3 Settings Bundles (Settings.bundle, Settings_Debug.bundle, Settings_Release.bundle). So you can preserve actual file after taking build.

Lal Krishna
  • 15,485
  • 6
  • 64
  • 84