最佳实践:iOS App 创建免费版和付费版时如何处理代码差异? [英] Best Practice: How to handle code differences for iOS App when creating free and paid version?
问题描述
我想在 AppStore 上发布两个版本的 iOS 应用程序.
I want to release two versions, of my iOS App on the AppStore.
一个是付费的,另一个是免费的.截至目前,我的付费应用程序代码已完成.现在我想为免费应用添加更多的 iAd 和 InAppPurchase 代码.
One is paid and other is free. As of now my code is finished for the paid App. Now I want to add more code for iAd and InAppPurchase's for the free app.
维护两个版本的最佳方法是什么?我正在考虑复制 Xcode 项目或在我的 git 存储库中创建一个分支.
What is the best approach for maintaining the two versions? I was thinking about copying the Xcode Project or creating a branch in my git repo.
推荐答案
如果你分支或复制项目,你就会为自己在未来的道路上制造维护噩梦.
If you branch or copy the project you're creating a maintenance nightmare for yourself down the road.
在同一个项目中创建一个单独的目标,具体的差异可以通过代码中的#ifdef块来处理.向每个目标添加定义以指定您是构建付费版本还是免费版本.
Create a separate target in the same project, specific differences can be handled via #ifdef blocks in the code. Add defines to each target to specify whether you're building paid or free versions.
== 添加 ==
要定义每个目标符号,请转到目标的构建设置,向下滚动直到找到 Apple LLVM 5.1 - 预处理块,更改特定于目标的设置以添加所需的符号(FREE_BUILD=1 或 PAID_BUILD=1 例如)
To define the per target symbols go to build setting for the target, scroll way down until you find the Apple LLVM 5.1 - Preprocessing block, the change the target-specific settings to add your desired symbol (FREE_BUILD=1 or PAID_BUILD=1 e.g.)
要添加目标特定代码,您可以在代码中使用该定义的符号:
To add target specific code you can then use that defined symbol in your code as:
// some code here
#if FREE_BUILD
// Some code that only gets compiled for the free target here
#elif PAID_BUILD
// Some code that only gets compiled for the paid target here
#else
// Just in case because I'm a paranoid sob
#error Must define FREE_BUILD or PAID_BUILD
#endif
这篇关于最佳实践:iOS App 创建免费版和付费版时如何处理代码差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!