一个代码库中三个略有不同的应用程序 [英] Three slightly different Apps from one code base
问题描述
Hy我希望有三个应用依赖,基于相同的代码:
-
MyAppDevelopment
(从部署到设备的Xcode构建) -
MyAppPreview
(Beta测试) -
MyApp
(发布)
应该可以在设备上安装所有三个应用程序,并且他们有自己的图标,以便在视觉上很好地区分它们。 / p>
现在我知道我可能有三个不同的目标及其各自的 Info.plist
文件,但我宁愿使用Xcode的配置,这样我就不必维护三个不同的目标。这是否可能使用配置,问题是App标识符存储在 Info.plist
文件中,该文件可以按目标定义...
为不同版本的应用程序使用不同的目标提供了更大的灵活性,并允许您在指定不同的plist文件后轻松更改包标识符和图标等每个目标。但是,配置与Xcode集成得更深,您可以根据配置调整任何构建设置
。
更多的研究我想出了如何只用一个目标来获得两全其美:
- 在Xcode中创建所需的配置:
ProjectName> ProjectName>信息
。例如:
- 调试
- 预览
- 发布
- 现在这三种配置可用于所有构建设置。
-
三个应用程序应该是co - 存在于设备上。
我希望能够在一台设备上拥有该应用程序的所有三个版本,因为这三种类型都需要不同的捆绑标识符。原始标识符可以是com.company。$ {PRODUCT_NAME:rfc1034identifier}
。
- 要实现此目的,请转到
MyProject> MyApp(目标)>构建设置
并单击按钮(+)添加构建设置
-
添加新的key
$ {APP_ID}
并设置这样的值并注意release
配置不应该有后缀:APP_ID> 'com.company.MyApp-debug'
> 'com.company.MyApp-preview'
> 'com.company.MyApp'
- 现在在
Info.plist中
将捆绑标识符
值更改为$ {APP_ID}
- 要实现此目的,请转到
-
您可以使用
捆绑显示名称
或图标
属性,以便您可以一目了然地轻松区分应用程序。 - 您可以设置
预处理器宏
对于您的配置,以便能够检测代码中的当前配置。默认情况下,debug
配置完成此操作:DEBUG = 1
。
优点
- 由于三个应用程序都有自己的标识符,因此您不会覆盖在Xcode中测试当前应用程序时的最新预览版本。
- 很好地集成到Xcode中并提供高度灵活性
现在可以根据配置单独更改所有构建设置 - 通过克隆Xcode中的现有配置可以轻松添加新配置
- 无需其他目标
目标是恕我直言完全不同的工件,例如具有不同代码库的库或测试目标。 - 如果需要,可以在代码中使用配置。
- 不同的服务URL等可用于不同的环境。请参阅此精彩帖子(感谢Jonah!)显示如何使用特殊的
plist
文件来执行此操作。 - 不使用任何难以维护的hacky脚本
缺点
-
随着使用目标可以从一种类型的App中排除某些框架。例如,您可以从应用程序的
debug
版本中排除一些分析库。 -
更新:您不能对用户定义的构建设置使用
com.company。$ {PRODUCT_NAME:rfc1034identifier}
等替换。因此,在这种情况下,您必须写出捆绑包整个捆绑包标识符。 -
更新:应该进行的一些设置配置感知移动到构建设置的用户定义部分,这可能会让一些开发人员感到不寻常。
结果
结果http://i.minus.com/jbwPgEiBra39dL .png
Hy there I would like to have three apps depending, which are based on the same code:
MyAppDevelopment
(Builds from Xcode that are deployed to the device)MyAppPreview
(Beta testing)MyApp
(Release)
It should be possible to have all of the three Apps installed on a device and they'd have their own icon to nicely distinguish them visually.
Now I know that I could have three different targets with their respective Info.plist
file, but I would rather use Xcode's configurations so that I don't have to maintain three different targets. Is this possible using configurations, the problem is that the App identifier is stored in the Info.plist
file, which can be defined per-target...
Using different targets for different editions of Apps provides more flexibility and lets you easily change the bundle identifier and the icon etc once you specify a different plist file per target. However, the configurations are more deeply integrated with Xcode and you can adjust any build setting
per configuration.
After some more research I figured out how to get the best of both worlds with just one target:
- Create the desired configurations in Xcode:
ProjectName > ProjectName > Info
. For example:- Debug
- Preview
- Release
- Now these three configurations are available for all the build settings.
The three Apps should co-exist on a device. I want to be able to have all three versions of the App on one device, for this all three types need a different bundle identifier. The original Identifier could be
com.company.${PRODUCT_NAME:rfc1034identifier}
.- To achieve this go to
MyProject > MyApp (Target) > Build settings
and click on the button(+) Add Build Setting
Add the new key
${APP_ID}
and set the values like this and note that therelease
configuration should not have a suffix:APP_ID > 'com.company.MyApp-debug' > 'com.company.MyApp-preview' > 'com.company.MyApp'
- Now in your
Info.plist
change theBundle Identifier
value to${APP_ID}
- To achieve this go to
You can do the same with the
Bundle Display Name
or theIcon
attribute so that you can easily distinguish the app at one glance.- You can set
Preprocessor macros
for your configurations in order to be able to detect the current configuration in your code. This is done by default for thedebug
configuration:DEBUG=1
.
Advantages
- Since the three Apps have their own identifier, you won't override the latest preview build when testing the current App in Xcode.
- Nicely integrated into Xcode and offers a high flexibility
All build settings can now individually be changed per configuration - New configurations can easily be added by cloning existing configurations within Xcode
- No need for additional targets
Targets are IMHO better for completely different artifacts like libraries or testing targets that have a different code base. - The configurations can be used in code if required.
- Different Service URLS etc. can be used for different environments. See this great post (Thanks to Jonah!) that shows how to do this using a special
plist
file. - No use of any hacky scripts which are hard to maintain
Disadvantages
With using targets it would be possible to exclude some frameworks from a type of App. So for example you could exclude some analytics library from the
debug
edition of your App.Update: You can't use substitutions like
com.company.${PRODUCT_NAME:rfc1034identifier}
for User defined Build Settings. So you'll have to write out the bundle whole bundle identifier in this case.Update: Some settings which should be made "configuration aware" move to the User-Defined section of the Build Settings, which might feel unusual for some developers.
The result
Result http://i.minus.com/jbwPgEiBra39dL.png
这篇关于一个代码库中三个略有不同的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!