5

So I'm following a tutorial that shows how to use the same codebase to build both a FREE and PAID version of an app.

It shows how to set up a DEFINE for "FREE" and I've got all that stuff working fine. What seems to be glossed over, is how to deal with this class definition. For the FREE app, it needs to be delegates for GADBannerViewDelegate, GADInterstitialDelegate, while the PAID version does not.

So I was hoping to set up something like this:

#if FREE
class GameViewController:    UIViewController, GKGameCenterControllerDelegate,  GADBannerViewDelegate, GADInterstitialDelegate {
#else
class GameViewController:    UIViewController, GKGameCenterControllerDelegate{
#endif

But that's not valid, and I after reading the docs, I understand why. What I don't understand, is how to deal with this. As a workaround, I figured I'd just make the PAID version have those GoogleAd delegates as well. But then Apple rejected my app, because including that makes it look like my app is serving up ads, when it isn't, and that's against the rules.

So for now, whenever I build the PAID vs FREE app, I'm just manually editing the code to change the declaration. It works, but is dumb. There's got to be a way to automate this, right?

1 Answer 1

5

You can use extension to implement protocols:

class GameViewController: UIViewController, GKGameCenterControllerDelegate {

    #if FREE
    var bannerView: GABannerView!
    var interstitial: GADInterstitial!
    #endif

    override func viewDidLoad() {
        super.viewDidLoad()

        #if FREE
        bannerView = GADBannerView(adSize:kGADAdSizeBanner)
        bannerView.delegate = self

        interstitial = GADInterstitial(adUnitID: "...")
        interstitail.delegate = self

        // ... other FREE stuff
        #endif

        // common stuff
    }
}

#if FREE
extension GameViewController: GADBannerViewDelegate, GADInterstitialDelegate {
    // Ad delegate methods
}
#endif
Sign up to request clarification or add additional context in comments.

1 Comment

.. and put the extension in a different file, referenced only by the "free" target.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.