两个版本的 iOS 应用程序 - 免费和付费 - 如何有条件地更改 Xcode 中的项目 ID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7975729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:18:31  来源:igfitidea点击:

Two versions of iOS app - Free and Paid - how to conditionally change project ID in Xcode?

iphoneiosxcode

提问by alexeypro

I have my app with ID com.mydomain.AppName which is a paidversion.

我有一个 ID 为 com.mydomain.AppName 的应用程序,它是付费版本。

I decided to introduce freeversion as well, and through my code I easily add ads/remove some functionality with simple #defined/#ifdef business.

我决定也推出免费版本,通过我的代码,我可以轻松地添加广告/删除一些简单的#defined/#ifdef 业务功能。

However, I do need my app ID to be different for free version. How do I do this conditionally (i.e. #ifdef FREE_VERSION ... etc.) for my app?

但是,我确实需要我的应用 ID 与免费版本不同。我如何有条件地为我的应用程序执行此操作(即 #ifdef FREE_VERSION ... 等)?

回答by JScarry

This question was answered in a previous post

这个问题在之前的帖子中得到了解答

The basic idea is that you create two targets and then either use #ifdefs or create separate files to control the content in the two targets. Creating another target is dead simple. Just right-click on your existing target and duplicate it. Give it the name that you want for the free app.

基本思想是创建两个目标,然后使用#ifdefs 或创建单独的文件来控制两个目标中的内容。创建另一个目标非常简单。只需右键单击您现有的目标并复制它。为免费应用程序指定您想要的名称。

In your case, you'll probably want to have different icons for the Free and Paid game, so create two icon folders—one called Free-Icons and the other called Paid-Icons. Put them in the project folder and when importing attach them to one of the targets.

在您的情况下,您可能希望免费和付费游戏有不同的图标,因此创建两个图标文件夹——一个名为 Free-Icons,另一个名为 Paid-Icons。将它们放在项目文件夹中,并在导入时将它们附加到目标之一。

I duplicated the original Info.plist and Prefix.pch files and gave them different names but you could use the same names, just put them in different folders. You'll need to adjust the build settings for each target to reflect the new names.

我复制了原始的 Info.plist 和 Prefix.pch 文件,并为它们指定了不同的名称,但您可以使用相同的名称,只需将它们放在不同的文件夹中即可。您需要调整每个目标的构建设置以反映新名称。

You might also have less content in the free app. Just select the sounds and pictures that are only in the paid app and in the inspector mark the Target Membership as just the paid app.

您的免费应用程序中的内容也可能较少。只需选择仅在付费应用程序中的声音和图片,并在检查器中将目标会员标记为仅付费应用程序。

You'll also need to edit your schemes as so that you can build two versions. I just finished doing this for a project that I'm working on and it took about two hours from start to finish to find everything that needed changed. I'm guessing I could add another version in about 15 minutes now that I know what I'm doing.

您还需要编辑您的方案,以便您可以构建两个版本。我刚刚为我正在进行的一个项目完成了这项工作,从开始到结束花了大约两个小时才找到需要更改的所有内容。我猜我可以在大约 15 分钟内添加另一个版本,因为我知道我在做什么。

This way of doing things is way better than duplicating the code or swapping the content out in one code base because you can easily switch back and forth between targets to make sure everything works when you make changes.

这种做事方式比在一个代码库中复制代码或交换内容要好得多,因为您可以轻松地在目标之间来回切换,以确保在进行更改时一切正常。

回答by Aditya Kumar Pandey

You could achieve this by having different XCode projects - one for each type of app that rely on common code (aka library XCode project(s)). One XCode project would be for paid app, and would have different macros, setup functions. The other XCode project would be for free app. Both the apps's projects can include shared sources - which would be compiled based on macros (PAIDor FREE) etc.

您可以通过拥有不同的 XCode 项目来实现这一点——每种类型的应用程序都依赖于公共代码(又名库 XCode 项目)。一个 XCode 项目将用于付费应用程序,并具有不同的宏、设置功能。另一个 XCode 项目将是免费应用程序。两个应用程序的项目都可以包含共享源 - 将基于宏(付费免费)等编译。