最佳实践:如何建立免费和付费版本时,处理code的差别为iOS应用? [英] Best Practice: How to handle code differences for iOS App when creating free and paid version?

查看:201
本文介绍了最佳实践:如何建立免费和付费版本时,处理code的差别为iOS应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发布在AppStore上两个版本我的iOS应用程序的。

I want to release two versions, of my iOS App on the AppStore.

一是支付等都是免费的。
截至目前我的code完成的付费应用。
现在,我想添加更多code代表的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.

什么是保持两个版本的最佳方法?
我在想复制在X code项目或在我的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.

在同一项目中创建一个单独的目标,具体的差异可以通过在code #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.

== == ADDED

== ADDED ==

要定义每个目标的符号去建造设定为目标,滚动方式,直到找到苹果LLVM 5.1 - preprocessing块,变化的具体目标的设置来添加您所需的符号(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.)

要添加特定目标code则可以使用定义的符号在你的code为:

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

这篇关于最佳实践:如何建立免费和付费版本时,处理code的差别为iOS应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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