简体   繁体   English

如何基于一个xcode项目构建Lite和Full版本的iPhone应用程序?

[英]How to build both Lite and Full version of iPhone app based on one xcode project?

I do not want to maintain two sets of code. 我不想维护两组代码。 I just need to limit some features in the Lite version and add some advertisements on it. 我只需要限制精简版的某些功能,并在其上添加一些广告。

How to do that? 怎么做?

Create multiple targets. 创建多个目标。

You can vary build configurations by right-clicking on a target and selecting Get Info. 您可以通过右键单击目标并选择“获取信息”来更改构建配置。 From there, you can do things like change which Info.plist file it's looking at (to do things like add "Lite" to the name and change the icon/load images) and set compiler flags so that you can #ifdef in places. 从那里,您可以执行诸如更改其正在查看的Info.plist文件的操作(进行诸如将“ Lite”添加到名称并更改图标/加载图像之类的操作)并设置编译器标志,以便可以在#ifdef的地方#ifdef

If there are lots of files that are only applicable in the full version, then you can right-click on them and remove them from the Lite target to make a smaller app. 如果有很多仅适用于完整版本的文件,则可以右键单击它们,然后将它们从Lite目标中删除,以制作一个较小的应用程序。

I've experimented with various alternatives, such as multiple configurations, and I keep coming back to multiple targets. 我已经尝试了多种选择,例如多种配置,并且我不断回到多个目标。 I usually have at least three defined - Development, Ad hoc and App Store, each with their own particular settings. 我通常至少定义了三个-开发,临时和App Store,每个都有自己的特定设置。

Add an additional target to your Xcode project by duplicating the existing one. 通过复制现有目标,将另一个目标添加到您的Xcode项目中。 Define a macro in the new target (under "preprocessor macros" in build settings), something like "macroIsFreeVersion" 在新目标中定义一个宏(在构建设置的“预处理器宏”下),类似于“ macroIsFreeVersion”

Now you can do this: 现在您可以执行以下操作:

#ifdef macroIsFreeVersion
  // code that will only execute in the free version here
#endif

and this: 和这个:

#ifndef macroIsFreeVersion
   // code for only the paid version goes here
#endif

You will need to make additional changes for the bundle id, provisioning profile, etc. All the stuff you did to put your paid version into the store. 您将需要对捆绑包ID,供应配置文件等进行其他更改。将付费版本放入商店时所做的所有工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM