两个版本的iOS应用程序 - 免费和付费 - 如何在XCode中有条件地更改项目ID? [英] Two versions of iOS app - Free and Paid - how to conditionally change project ID in XCode?

查看:130
本文介绍了两个版本的iOS应用程序 - 免费和付费 - 如何在XCode中有条件地更改项目ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序ID为com.mydomain.AppName,这是付费版本。

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

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

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

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

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?

推荐答案

上一篇文章

基本思路是创建两个目标,然后使用#ifdefs或单独创建文件来控制两个目标中的内容。创建另一个目标很简单。只需右键单击现有目标并将其复制即可。为它提供免费应用程序所需的名称。

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.

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

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.

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

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.

您可能在免费应用中的内容也较少。只需选择仅在付费应用中和检查员中将目标成员资格标记为付费应用的声音和图片。

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.

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

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.

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

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.

这篇关于两个版本的iOS应用程序 - 免费和付费 - 如何在XCode中有条件地更改项目ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆