将目标添加到Xcode项目

时间:2023-01-13 20:37:08

I have an iPhone application which is currently in the app store. I want to make what is effectively exactly the same application, but which is free of charge and features ads.

我有一个iPhone应用程序,目前在应用程序商店中。我想制作实际上完全相同的应用程序,但它是免费的并且具有广告功能。

My plan was to effectively just copy the project, create a new one and add ads into the code and release as separate app. However, someone mentioned that the best solution would be to add an additional target to the existing application, providing two binaries at run time.

我的计划是有效地复制项目,创建一个新项目并在代码中添加广告并作为单独的应用程序发布。但是,有人提到最好的解决方案是在现有应用程序中添加一个额外的目标,在运行时提供两个二进制文件。

Seems like a good solution to me, however I am a little confused as to how I would go about altering the code to have ads built into the new target, and leaving the original untouched?

对我来说似乎是一个很好的解决方案,但是我对如何改变代码以将广告内置到新目标中并保持原始状态保持不变感到有些困惑?

3 个解决方案

#1


7  

I followed this tutorial which, although old, was basically the same for xcode 4. I duplicated the target and p-list, making sure I was able to run it with changes and not affect the full version target.

我遵循了这个教程,虽然陈旧,但基本上与xcode 4相同。我复制了目标和p列表,确保我能够通过更改运行它而不影响完整版本目标。

I then duplicated the .xib files that would be different. If you look under the project settings, somewhere you can find a list which allows you to choose which resources are included. Include the lite version's xibs in the the lite version, and the full version's in the full respectively. Then you will be able to edit each without affecting the other.

然后我复制了不同的.xib文件。如果您在项目设置下查看某个地方,您可以找到一个列表,允许您选择包含哪些资源。在Lite版本中包含lite版本的xib,在完整版本中分别包含完整版本。然后,您将能够编辑每个而不影响另一个。

The icons and images can be changed in the same way. Simply create a lite version icon set or other set of images and include the lite icons in the lite target's resource settings instead of the full version's images.

图标和图像可以以相同的方式更改。只需创建精简版图标集或其他图像集,并在精简目标的资源设置中包含精简图标,而不是完整版本的图像。

Also, you'll want to create some preprocessor macros. In the build tab look for them, and crete a macro called LITE_VERSION (or whatever you want, it doesn't really matter) for every preprocessing option - debug, distribution and release.

此外,您还需要创建一些预处理器宏。在构建选项卡中查找它们,并为每个预处理选项 - 调试,分发和发布创建一个名为LITE_VERSION(或任何你想要的,它并不重要)的宏。

That allows you to add differing code in the same .h and .m files. Simply use

这允许您在相同的.h和.m文件中添加不同的代码。简单地使用

#ifdef LITE_VERSION
// Lite version only code here
#endif

to separate the two. You can also use #ifndef LITE_VERSION to add code only to the full version.

将两者分开。您还可以使用#ifndef LITE_VERSION仅将代码添加到完整版本。

That's it! After all of the above steps, you should be able to edit the lite version's .xib files, put code into the lite or full version only, and have separate images and icons for each.

而已!完成上述所有步骤后,您应该能够编辑lite版本的.xib文件,只将代码放入精简版或完整版,并为每个文件分别设置图像和图标。

#2


2  

XenElement's answer is correct. But you should see the best practice to do it. You should have an identifier class to check for targets. If you use macros everywhere in the code, it won't seem good for you and other developers as well. In this little blog post you can see how to create that kind of an identifier class and learn some best practices about targets in xcode.

XenElement的答案是正确的。但你应该看到最好的做法。您应该有一个标识符类来检查目标。如果你在代码中的任何地方都使用宏,那对你和其他开发人员来说似乎也不好。在这篇小博客文章中,您可以看到如何创建这种标识符类,并了解有关xcode中目标的一些最佳实践。

#3


0  

I followed this Just2us: How to create multiple targets for Xcode iPhone Projects tutorial.

我按照这个Just2us:如何为Xcode iPhone Projects教程创建多个目标。

I decided change step-3 with Stu's clue, setting FULL_VERSION explicitly in the paid version.

我决定用Stu的线索更改步骤3,在付费版本中明确设置FULL_VERSION。

"To address the concern of not having accidentally LITE_VERSION defined as a macro preprocessor (thus releasing a full version accidentally), I put this little snippet of code in a header file (it just needs to be somewhere in the code base , just make sure that is common to all configurations)":

“为了解决没有意外地将LITE_VERSION定义为宏预处理器(从而意外地发布完整版本)的问题,我将这一小段代码放在头文件中(它只需要在代码库中的某个地方,只需确保这对所有配置都是通用的)“:

#ifndef LITE_VERSION
    #ifndef FULL_VERSION
        #error You probably forgot to specify if this is the Lite or Full version of the app
    #endif
#endif

PS: I wrote the code above right after the #import in AppDelegate.

PS:我在AppDelegate的#import之后写了上面的代码。

#1


7  

I followed this tutorial which, although old, was basically the same for xcode 4. I duplicated the target and p-list, making sure I was able to run it with changes and not affect the full version target.

我遵循了这个教程,虽然陈旧,但基本上与xcode 4相同。我复制了目标和p列表,确保我能够通过更改运行它而不影响完整版本目标。

I then duplicated the .xib files that would be different. If you look under the project settings, somewhere you can find a list which allows you to choose which resources are included. Include the lite version's xibs in the the lite version, and the full version's in the full respectively. Then you will be able to edit each without affecting the other.

然后我复制了不同的.xib文件。如果您在项目设置下查看某个地方,您可以找到一个列表,允许您选择包含哪些资源。在Lite版本中包含lite版本的xib,在完整版本中分别包含完整版本。然后,您将能够编辑每个而不影响另一个。

The icons and images can be changed in the same way. Simply create a lite version icon set or other set of images and include the lite icons in the lite target's resource settings instead of the full version's images.

图标和图像可以以相同的方式更改。只需创建精简版图标集或其他图像集,并在精简目标的资源设置中包含精简图标,而不是完整版本的图像。

Also, you'll want to create some preprocessor macros. In the build tab look for them, and crete a macro called LITE_VERSION (or whatever you want, it doesn't really matter) for every preprocessing option - debug, distribution and release.

此外,您还需要创建一些预处理器宏。在构建选项卡中查找它们,并为每个预处理选项 - 调试,分发和发布创建一个名为LITE_VERSION(或任何你想要的,它并不重要)的宏。

That allows you to add differing code in the same .h and .m files. Simply use

这允许您在相同的.h和.m文件中添加不同的代码。简单地使用

#ifdef LITE_VERSION
// Lite version only code here
#endif

to separate the two. You can also use #ifndef LITE_VERSION to add code only to the full version.

将两者分开。您还可以使用#ifndef LITE_VERSION仅将代码添加到完整版本。

That's it! After all of the above steps, you should be able to edit the lite version's .xib files, put code into the lite or full version only, and have separate images and icons for each.

而已!完成上述所有步骤后,您应该能够编辑lite版本的.xib文件,只将代码放入精简版或完整版,并为每个文件分别设置图像和图标。

#2


2  

XenElement's answer is correct. But you should see the best practice to do it. You should have an identifier class to check for targets. If you use macros everywhere in the code, it won't seem good for you and other developers as well. In this little blog post you can see how to create that kind of an identifier class and learn some best practices about targets in xcode.

XenElement的答案是正确的。但你应该看到最好的做法。您应该有一个标识符类来检查目标。如果你在代码中的任何地方都使用宏,那对你和其他开发人员来说似乎也不好。在这篇小博客文章中,您可以看到如何创建这种标识符类,并了解有关xcode中目标的一些最佳实践。

#3


0  

I followed this Just2us: How to create multiple targets for Xcode iPhone Projects tutorial.

我按照这个Just2us:如何为Xcode iPhone Projects教程创建多个目标。

I decided change step-3 with Stu's clue, setting FULL_VERSION explicitly in the paid version.

我决定用Stu的线索更改步骤3,在付费版本中明确设置FULL_VERSION。

"To address the concern of not having accidentally LITE_VERSION defined as a macro preprocessor (thus releasing a full version accidentally), I put this little snippet of code in a header file (it just needs to be somewhere in the code base , just make sure that is common to all configurations)":

“为了解决没有意外地将LITE_VERSION定义为宏预处理器(从而意外地发布完整版本)的问题,我将这一小段代码放在头文件中(它只需要在代码库中的某个地方,只需确保这对所有配置都是通用的)“:

#ifndef LITE_VERSION
    #ifndef FULL_VERSION
        #error You probably forgot to specify if this is the Lite or Full version of the app
    #endif
#endif

PS: I wrote the code above right after the #import in AppDelegate.

PS:我在AppDelegate的#import之后写了上面的代码。